@@ -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