diff --git a/bugheist/urls.py b/bugheist/urls.py index fbaf97eaf..5e5b6c257 100644 --- a/bugheist/urls.py +++ b/bugheist/urls.py @@ -50,12 +50,12 @@ url(r'^favicon\.ico$', favicon_view), url(r'^sendgrid_webhook/$', csrf_exempt(InboundParseWebhookView.as_view()), name='inbound_event_webhook_callback'), url(r'^issue/comment/add/$',comments.views.add_comment, name='add_comment'), - # url(r'^issue/comment/(?P\d+)/$',comments.views.AddComment, name='add_comment'), + url(r'^issue/comment/delete/$',comments.views.delete_comment, name='delete_comment'), url(r'^issue/comment/(?P\d+)/edit/$',comments.views.EditCommentPage, name='edit_comment'), url(r'^issue/comment/(?P\d+)/update/$',comments.views.EditComment, name='update_comment'), - url(r'^issue/comment/(?P\d+)/delete/$',comments.views.DeleteComment, name='delete_comment'), url(r'^social/$', TemplateView.as_view(template_name="social.html")), url(r'^search/$', website.views.search), + ) + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) diff --git a/comments/views.py b/comments/views.py index 7266f80cc..7f7abb94d 100644 --- a/comments/views.py +++ b/comments/views.py @@ -22,13 +22,19 @@ def add_comment(request): 'user':request.user},) -@login_required(login_url="/accounts/login/") -def DeleteComment(request,pk): - comment = get_object_or_404(Comment,pk=pk) - if request.user.username!=comment.author: - return HttpResponseRedirect(os.path.join('/issue',str(pk))) - comment.delete() - return HttpResponseRedirect(os.path.join('/issue',str(comment.issue.pk))) +@login_required(login_url='/accounts/login') +def delete_comment(request): + if request.method=="POST": + issue = Issue.objects.get(pk=request.POST['issue_pk']) + all_comment = Comment.objects.filter(issue=issue) + comment = Comment.objects.get(pk=int(request.POST['comment_pk'])) + if request.user.username!=comment.author: + return HttpResponse("Cannot delete this comment") + comment.delete() + return render(request,'comments.html',{'all_comment':all_comment, + 'user':request.user},) + + @login_required(login_url="/accounts/login/") def EditComment(request,pk): diff --git a/website/templates/comments.html b/website/templates/comments.html index 98b824efe..73ac86574 100644 --- a/website/templates/comments.html +++ b/website/templates/comments.html @@ -7,7 +7,8 @@  commented on 
{{ comment.created_date }}
{% if user.username == comment.author %} Edit - Delete + Delete + {% endif %}
diff --git a/website/templates/issue.html b/website/templates/issue.html index 071da0e35..346f9ae7b 100644 --- a/website/templates/issue.html +++ b/website/templates/issue.html @@ -202,7 +202,8 @@

Comments:

 commented on 
{{ comment.created_date }}
{% if user.username == comment.author %} Edit - Delete + Delete + {% endif %}
@@ -242,6 +243,28 @@

Comments:

}); }); + + $('body').on('click', '.del_comment', function (e){ + + e.preventDefault(); + $.ajax({ + type: 'POST', + url: "/issue/comment/delete/", + data:{ + comment_pk:$(this).attr('name'), + issue_pk: $('#issue_pk').val(), + csrfmiddlewaretoken: $('input[name=csrfmiddlewaretoken]').val(), + + }, + success: function(data) { + $('#target_div').html(data); + }, + error: function(result) { + // alert($('#issue_pk').val()); + } + }); +}); +