Skip to content
This repository was archived by the owner on May 7, 2024. It is now read-only.

Commit 245cb07

Browse files
committed
Migration project comments to django
1 parent d936adf commit 245cb07

File tree

4 files changed

+38
-6
lines changed

4 files changed

+38
-6
lines changed

app.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
(re.compile(r'/\w+/\w+/raw'), django_app),
3737
(re.compile(r'/\w+/\w+/browsefiles'), django_app),
3838
(re.compile(r'/\w+/\w+/code_review'), django_app),
39+
(re.compile(r'/\w+/\w+/comments'), django_app),
3940
(re.compile(r'/vilya'), django_app),
4041
(re.compile(r'/.*'), web)]
4142

vilya/urls.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@
108108
url(r'^(?P<username>\w+)/(?P<projectname>\w+)/browsefiles/?$', project.browsefiles, name="project_browsefiles"),
109109
url(r'^(?P<username>\w+)/(?P<projectname>\w+)/code_review/(?P<id>[0-9]+)/delete/?$', project.codereview_delete, name="project_codereview_delete"),
110110
url(r'^(?P<username>\w+)/(?P<projectname>\w+)/code_review/(?P<id>[0-9]+)/edit/?$', project.codereview_edit, name="project_codereview_edit"),
111+
url(r'^(?P<username>\w+)/(?P<projectname>\w+)/comments/?$', project.comment, name="project_comment"),
112+
url(r'^(?P<username>\w+)/(?P<projectname>\w+)/comments/new/?$', project.comment_new, name="project_comment_new"),
113+
url(r'^(?P<username>\w+)/(?P<projectname>\w+)/comments/(?P<id>[0-9]+)/?$', project.comment_delete, name="project_comment_delete"),
111114
url(r'^(?P<username>\w+)/(?P<projectname>\w+)/watchers/?$', project.watchers, name="project_watchers"),
112115
url(r'^(?P<username>\w+)/(?P<projectname>\w+)/forkers/?$', project.forkers, name="project_forkers"),
113116
url(r'^(?P<username>\w+)/(?P<projectname>\w+)/archive/(?P<revision>\w+)/?$', project.archive, name="project_archive"),

vilya/views/__init__.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
from vilya.views.uis.pull import PullUI, PullsUI
1717
from vilya.views.uis.dashboard import DashboardUI
1818
from vilya.views.uis.compare import CompareUI
19-
from vilya.views.uis.comments import CommentUI
2019
from vilya.views.uis.line_comments import LineCommentUI
2120
from vilya.views.uis.pr_comment import PrCommentUI
2221
from vilya.views.uis.issue import IssueBoardUI, IssueCommentUI
@@ -125,7 +124,7 @@ def _q_lookup(self, request, url_part):
125124

126125
class CodeUI:
127126
_q_exports = [
128-
'hooks', 'graph', 'commit', 'pull', 'newpull', 'comments',
127+
'hooks', 'graph', 'commit', 'pull', 'newpull',
129128
'compare', 'line_comments', 'pulls',
130129
'docs', 'remove', 'pr_comment', 'issues',
131130
'issue_comments', 're_index_docs', 'src_index',
@@ -202,10 +201,6 @@ def pulls(self):
202201
def dashboard(self):
203202
return DashboardUI(self.proj_name)
204203

205-
@property
206-
def comments(self):
207-
return CommentUI(self.proj_name)
208-
209204
@property
210205
def line_comments(self):
211206
return LineCommentUI(self.proj_name)

vilya/views/django/project.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -680,3 +680,36 @@ def codereview_edit(request, username, projectname, id):
680680
return HttpResponse(json.dumps(dict(
681681
r=0, html=st('/pull/ticket_linecomment.html', **locals()))))
682682
return HttpResponse(json.dumps(dict(r=1)))
683+
684+
685+
def comment(request, username, projectname):
686+
from vilya.models.comment import latest
687+
return HttpResponse("Last comments list TODO" + str(latest()))
688+
689+
690+
@csrf_exempt
691+
def comment_new(request, username, projectname):
692+
from vilya.models.project import CodeDoubanProject
693+
from vilya.models.comment import Comment
694+
name = '/'.join([username, projectname])
695+
project = CodeDoubanProject.get_by_name(name)
696+
user = request.user
697+
ref = request.POST.get('ref')
698+
assert ref, "comment ref cannot be empty"
699+
content = request.POST.get('content', '')
700+
new_comment = Comment.add(project, ref, user.name, content)
701+
702+
return HttpResponseRedirect("/%s/commit/%s#%s" %
703+
(name, ref, new_comment.uid))
704+
705+
706+
@csrf_exempt
707+
def comment_delete(request, username, projectname, id):
708+
from vilya.models.comment import Comment
709+
if request.method == 'DELETE':
710+
# FIXME: 不用验证user?
711+
ok = Comment.delete(id)
712+
if not ok:
713+
raise Http404("Unable to delete comment %s" % id)
714+
return HttpResponse('')
715+
return HttpResponse("Display comment %s TODO" % id)

0 commit comments

Comments
 (0)