Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions vilya/actions/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# -*- coding: utf-8 -*-

from ..core import Service
from .models import Action


class ActionService(Service):
__model__ = Action
29 changes: 29 additions & 0 deletions vilya/actions/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# -*- coding: utf-8 -*-

from datetime import datetime
from ..core import db
from ..libs.const import ACTION_TYPES


class Action(db.Model):
__tablename__ = 'actions'

id = db.Column(db.Integer(), primary_key=True)
type = db.Column(db.Integer(), default=ACTION_TYPES['comment'])
type_id = db.Column(db.Integer())
issue_id = db.Column(db.Integer())
creator_id = db.Column(db.Integer())
created_at = db.Column(db.DateTime(), default=datetime.utcnow)
updated_at = db.Column(db.DateTime(), default=datetime.utcnow, onupdate=datetime.utcnow)

@property
def comment(self):
from ..services import comments
return comments.get(id=self.type_id)

@property
def creator(self):
from ..services import users
if not self.creator_id:
return None
return users.get(id=self.creator_id)
8 changes: 8 additions & 0 deletions vilya/comments/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# -*- coding: utf-8 -*-

from ..core import Service
from .models import Comment


class CommentService(Service):
__model__ = Comment
15 changes: 15 additions & 0 deletions vilya/comments/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# -*- coding: utf-8 -*-

from flask_wtf import Form
from wtforms import TextField
from wtforms.validators import DataRequired as Required

__all__ = ['NewCommentForm', 'UpdateCommentForm']


class NewCommentForm(Form):
description = TextField('Description', validators=[Required()])


class UpdateCommentForm(Form):
description = TextField('Description', validators=[Required()])
24 changes: 24 additions & 0 deletions vilya/comments/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# -*- coding: utf-8 -*-

from datetime import datetime
from ..core import db
from ..libs.const import COMMENT_TYPES


class Comment(db.Model):
__tablename__ = 'comments'

id = db.Column(db.Integer(), primary_key=True)
type = db.Column(db.Integer(), default=COMMENT_TYPES['issue'])
description = db.Column(db.Text)
issue_id = db.Column(db.Integer())
creator_id = db.Column(db.Integer())
created_at = db.Column(db.DateTime(), default=datetime.utcnow)
updated_at = db.Column(db.DateTime(), default=datetime.utcnow, onupdate=datetime.utcnow)

@property
def creator(self):
from ..services import users
if not self.creator_id:
return None
return users.get(id=self.creator_id)
1 change: 1 addition & 0 deletions vilya/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
from .projects.forms import *
from .issues.forms import *
from .pullrequests.forms import *
from .comments.forms import *
37 changes: 31 additions & 6 deletions vilya/frontend/issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@
flash,
redirect,
url_for,
abort)
abort,
request,
jsonify)
from flask.ext.login import current_user
from ..services import projects, users, issues
from ..forms import NewIssueForm
from ..forms import NewIssueForm, NewCommentForm
from ..libs.const import ISSUE_TYPES
from . import route

bp = Blueprint('issue', __name__, url_prefix='/<u_name>/<p_name>/issues')
Expand Down Expand Up @@ -38,7 +41,7 @@ def index():
context['project'] = g.project
context['project_menu'] = 'Issues'
project = g.project
context['issues'] = issues.find(project_id=project.id)
context['issues'] = issues.find(project_id=project.id, type=ISSUE_TYPES['default'])
return render_template('issues/index.html', **context)


Expand Down Expand Up @@ -70,12 +73,34 @@ def create():


@route(bp, '/<id>')
def issue_index(id):
def issue(id):
context = {}
context['u_name'] = g.u_name
context['p_name'] = g.p_name
context['project'] = g.project
context['project_menu'] = 'Issues'
context['issue'] = issues.first(project_id=g.project.id,
number=id)
issue = issues.first(project_id=g.project.id,
number=id,
type=ISSUE_TYPES['default'])
context['issue'] = issue
context['new_comment_form'] = NewCommentForm()
context['actions'] = issue.actions
return render_template('issues/issue.html', **context)


@route(bp, '/<id>/comments', methods=['post'])
def issue_comment_index(id):
# TODO move to api
context = {}
context['u_name'] = g.u_name
context['p_name'] = g.p_name
issue = issues.first(project_id=g.project.id,
number=id,
type=ISSUE_TYPES['default'])
if request.method == 'POST':
form = NewCommentForm()
if form.validate_on_submit():
comment = issue.create_comment(creator=current_user, **form.data)
return redirect(url_for('.issue', id=id, **context))
# return jsonify(comment=comment)
return redirect(url_for('.issue', id=id, **context))
16 changes: 11 additions & 5 deletions vilya/frontend/templates/issues/issue.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
{% extends "projects/base.html" %}
{% from "issues/macros/comment.html" import render_issue_actions, render_issue_new_comment, render_issue_description %}

{% block sub_content %}
<div class="panel panel-default">
<div class="panel-heading">
<div class="panel-heading">
#{{issue.number}} {{issue.name}}
</div>
<div class="panel-body">
<p> {{issue.description}} </p>
</div>
</div>
<div class="panel-body">
<p>{{issue.description}}</p>
</div>
{{ render_issue_description(project, issue) }}
{{ render_issue_actions(project, issue, actions) }}
{% if new_comment_form %}
{{ render_issue_new_comment(project, current_user, issue, new_comment_form) }}
{% endif %}
</div>
{% endblock %}
188 changes: 188 additions & 0 deletions vilya/frontend/templates/issues/macros/comment.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
{% macro render_issue_updated_comment_form(project, issue, comment) -%}
<form accept-charset="utf-8" action="/{{project.full_name}}/issue_comments/{{issue.number}}"
class="js-comment-update" data-remote="" data-type="json" method="post">
<div style="margin:0;padding:0;display:inline">
<input name="utf8" type="hidden" value="✓">
<input name="_method" type="hidden" value="put">
<input name="authenticity_token" type="hidden" value="quvwgztylt0esgm9vv/71g0gpgvilf6ahohvxi4tigcnmdoof2gi4e2jhxkuob0hr15jvubu+j//r3w70xjbrw==">
</div>
<textarea class="comment-form-textarea js-comment-field js-quick-submit js-task-list-field js-size-to-fit js-suggester-field" id="issue-40807214-body" name="issue[body]" tabindex="1">
{{comment.description}}
</textarea>
<div class="form-actions">
<button type="submit" class="btn btn-sm btn-primary" tabindex="1" data-disable-with="">update comment</button>
<button type="button" tabindex="1" class="btn btn-sm btn-danger comment-cancel-button js-comment-cancel-button" data-confirm-text="are you sure you want to cancel? you have unsaved changes that will be reverted.">
cancel
</button>
</div>
</form>
{%- endmacro %}

{% macro render_issue_new_comment_form(project, issue, form) -%}
<form accept-charset="UTF-8" action="/{{project.full_name}}/issues/{{issue.number}}/comments" class="js-new-comment-form" data-remote="true" data-type="json" method="post">
{{ form.hidden_tag() }}
<div style="margin:0;padding:0;display:inline">
<input name="utf8" type="hidden" value="✓">
<input name="authenticity_token" type="hidden" value="VMx0TGr0Ya8tKEDSjsomA5xfAFFaHS30bt/Jw0/i8j+fI+I1VcrE5AHQ9MpUCjuH7YObGWAzFaMwJcjYhBWpFQ==">
</div>
<div class="timeline-comment">
<input type="hidden" name="issue" value="50">
<div class="js-previewable-comment-form js-suggester-container previewable-comment-form write-selected" data-preview-url="/preview?repository={{project.id}}">
<div class="comment-form-head tabnav">
<ul class="nav nav-tabs">
<li class="active"><a href="#" class="tabnav-tab write-tab js-write-tab selected">Write</a></li>
<li><a href="#" class="tabnav-tab preview-tab js-preview-tab">Preview</a></li>
</ul>
</div>
<div class="comment-form-error js-comment-form-error" style="display:none">
There was an error creating your Issue.
</div>
<div class="write-content js-write-bucket js-uploadable-container js-upload-markdown-image upload-enabled is-default"
data-upload-policy-url="/upload/policies/assets">
<textarea name="description" tabindex="1" id="new_comment_field" placeholder="Leave a comment"
class="input-contrast comment-form-textarea js-comment-field js-quick-submit js-size-to-fit js-quote-selection-target js-session-resumable js-suggester-field"></textarea>
</div>
<div class="preview-content">
<div class="comment">
<div class="comment-content">
<div class="comment-body markdown-body">
<p>Nothing to preview</p>
</div>
</div>
</div>
</div>
</div>
<div class="form-actions">
<div id="partial-new-comment-form-actions" class="js-socket-channel js-updatable-content" data-channel="douban/code:issue:29512662:state"
data-url="/douban/code/pull/50/show_partial?partial=form_actions">
<button type="submit" class="btn btn-primary" tabindex="2" data-disable-with="" data-disable-invalid="">
Comment
</button>
<button type="submit" name="comment_and_close" value="1" class="btn js-comment-and-button" tabindex="3"
data-comment-text="Close and comment" data-disable-with="">
Close issue
</button>
</div>
</div>
</div>
</form>
{%- endmacro %}

{% macro render_issue_description(project, issue) -%}
<div class="timeline-comment-wrapper js-comment-container">
<a href="/{{issue.creator.name}}">
<img alt="{{issue.creator.name}}" class="timeline-comment-avatar"
data-user="{{issue.creator.id}}" height="48" src="{{issue.creator.avatar_url}}" width="48">
</a>
<div id="issue-40807214" class="comment timeline-comment js-comment js-task-list-container current-user is-task-list-enabled" data-body-version="97c6ff07df2110d5a216983dffba336c">
<div class="timeline-comment-header ">
<div class="timeline-comment-actions">
<a class="octicon octicon-pencil js-comment-edit-button" data-skip-pjax="" href="#" title="edit comment" aria-label="edit comment"></a>
</div>
<div class="timeline-comment-header-text">
<strong>
<a href="/{{issue.creator.name}}" class="author">{{issue.creator.name}}</a>
</strong>
commented
<a href="#issue-40807214" class="timestamp">
<time datetime="2014-08-21t14:01:15z" is="relative-time" title="aug 21, 2014 10:01 pm gmt+08:00">{{issue.updated_at}}</time>
</a>
</div>
</div>
<div class="comment-content">
<p class="comment-form-stale">
the content you are editing has changed. reload the page and try again.
</p>
<div class="edit-comment-hide">
<div class="comment-body markdown-body markdown-format js-comment-body">
{{issue.description}}
</div>
</div>
<div class="context-loader">sending request…</div>
<div class="form-content js-write-bucket js-suggester-container js-uploadable-container js-upload-markdown-image upload-enabled is-default" data-upload-policy-url="/upload/policies/assets">
<form accept-charset="utf-8" action="/{{project.full_name}}/issues/{{issue.number}}"
class="js-comment-update" data-remote="" data-type="json" method="post">
<div style="margin:0;padding:0;display:inline">
<input name="utf8" type="hidden" value="✓">
<input name="_method" type="hidden" value="put">
<input name="authenticity_token" type="hidden" value="quvwgztylt0esgm9vv/71g0gpgvilf6ahohvxi4tigcnmdoof2gi4e2jhxkuob0hr15jvubu+j//r3w70xjbrw==">
</div>
<textarea class="comment-form-textarea js-comment-field js-quick-submit js-task-list-field js-size-to-fit js-suggester-field" id="issue-40807214-body" name="issue[body]" tabindex="1">
{{issue.description}}
</textarea>
<div class="form-actions">
<button type="submit" class="btn btn-sm btn-primary" tabindex="1" data-disable-with="">update comment</button>
<button type="button" tabindex="1" class="btn btn-sm btn-danger comment-cancel-button js-comment-cancel-button" data-confirm-text="are you sure you want to cancel? you have unsaved changes that will be reverted.">
cancel
</button>
</div>
</form>
</div>
<div class="comment-form-error comment-form-bottom js-comment-update-error"></div>
</div>
</div>
</div>
{%- endmacro %}

{% macro render_issue_actions(project, issue, actions) -%}
{% for a in actions %}
{{ render_issue_comment(project, issue, a.comment) }}
{% endfor %}
{%- endmacro %}

{% macro render_issue_comment_author_avatar(user) -%}
<a href="/{{user.name}}">
<img alt="{{user.name}}" class="timeline-comment-avatar"
data-user="{{user.id}}" height="48" src="{{user.avatar_url}}" width="48">
</a>
{%- endmacro %}

{% macro render_issue_comment(project, issue, comment) -%}
<div class="timeline-comment-wrapper js-comment-container">
<a href="/{{comment.creator.name}}"><img alt="{{comment.creator.name}}" class="timeline-comment-avatar" data-user="1050163" height="48" src="{{comment.creator.avatar_url}}" width="48"></a>
<div id="issue-40807214" class="comment timeline-comment js-comment js-task-list-container current-user is-task-list-enabled" data-body-version="97c6ff07df2110d5a216983dffba336c">
<div class="timeline-comment-header ">
<div class="timeline-comment-actions">
<a class="octicon octicon-pencil js-comment-edit-button" data-skip-pjax="" href="#" title="edit comment" aria-label="edit comment"></a>
</div>
<div class="timeline-comment-header-text">
<strong>
<a href="/{{comment.creator.name}}" class="author">{{comment.creator.name}}</a>
</strong>
commented
<a href="#issue-40807214" class="timestamp">
<time datetime="2014-08-21t14:01:15z" is="relative-time" title="aug 21, 2014 10:01 pm gmt+08:00">{{comment.created_at}}</time>
</a>
</div>
</div>
<div class="comment-content">
<p class="comment-form-stale">
the content you are editing has changed. reload the page and try again.
</p>
<div class="edit-comment-hide">
<div class="comment-body markdown-body markdown-format js-comment-body">
{{comment.description}}
</div>
</div>
<div class="context-loader">sending request…</div>
<div class="form-content js-write-bucket js-suggester-container js-uploadable-container js-upload-markdown-image upload-enabled is-default" data-upload-policy-url="/upload/policies/assets">
{{render_issue_updated_comment_form(project, issue, comment)}}
</div>
<div class="comment-form-error comment-form-bottom js-comment-update-error"></div>
</div>
</div>
</div>
{%- endmacro %}

{% macro render_issue_action() -%}
{%- endmacro %}

{% macro render_issue_new_comment(project, user, issue, form) -%}
<div class="timeline-comment-wrapper timeline-new-comment js-comment-container ">
<a href="/{{user.name}}">
<img alt="{{user.name}}" class="timeline-comment-avatar"
data-user="{{user.id}}" height="48" src="{{user.avatar_url}}" width="48">
</a>
{{render_issue_new_comment_form(project, issue, form)}}
</div>
{%- endmacro %}
Loading