Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Comment is deleted without page refresh Fixes #339 #342

Merged
merged 1 commit into from
Jul 10, 2017
Merged
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
4 changes: 2 additions & 2 deletions bugheist/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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<pk>\d+)/$',comments.views.AddComment, name='add_comment'),
url(r'^issue/comment/delete/$',comments.views.delete_comment, name='delete_comment'),
url(r'^issue/comment/(?P<pk>\d+)/edit/$',comments.views.EditCommentPage, name='edit_comment'),
url(r'^issue/comment/(?P<pk>\d+)/update/$',comments.views.EditComment, name='update_comment'),
url(r'^issue/comment/(?P<pk>\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)
20 changes: 13 additions & 7 deletions comments/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
3 changes: 2 additions & 1 deletion website/templates/comments.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
&nbsp;commented on&nbsp;<div class="date"> {{ comment.created_date }}</div>
{% if user.username == comment.author %}
<a class="btn btn-xs btn-primary" href="{% url 'comments.views.EditCommentPage' pk=comment.pk %}">Edit</a>
<a class="btn btn-xs btn-danger" href="{% url 'comments.views.DeleteComment' pk=comment.pk %}">Delete</a>
<a class="btn btn-xs btn-danger del_comment" name="{{ comment.pk }}">Delete</a>

{% endif %}
</div>
<div>
Expand Down
25 changes: 24 additions & 1 deletion website/templates/issue.html
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,8 @@ <h3>Comments:</h3>
&nbsp;commented on&nbsp;<div class="date"> {{ comment.created_date }}</div>
{% if user.username == comment.author %}
<a class="btn btn-xs btn-primary" href="{% url 'comments.views.EditCommentPage' pk=comment.pk %}">Edit</a>
<a class="btn btn-xs btn-danger" href="{% url 'comments.views.DeleteComment' pk=comment.pk %}">Delete</a>
<a class="btn btn-xs btn-danger del_comment" name="{{ comment.pk }}">Delete</a>

{% endif %}
</div>
<div>
Expand Down Expand Up @@ -242,6 +243,28 @@ <h3>Comments:</h3>

});
});

$('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());
}
});
});

</script>


Expand Down