From fc4c9c2ee8a3c6720216f663f868a0cba0144f59 Mon Sep 17 00:00:00 2001 From: Mohit Anand Date: Sun, 9 Jul 2017 07:08:03 +0530 Subject: [PATCH 1/2] Added ajax comment adding --- bugheist/urls.py | 4 +++- comments/views.py | 12 ++++++++---- website/templates/issue.html | 36 ++++++++++++++++++++++++++++++------ 3 files changed, 41 insertions(+), 11 deletions(-) diff --git a/bugheist/urls.py b/bugheist/urls.py index b52dd197e..fbaf97eaf 100644 --- a/bugheist/urls.py +++ b/bugheist/urls.py @@ -49,11 +49,13 @@ url(r'^stats/$', StatsDetailView.as_view()), url(r'^favicon\.ico$', favicon_view), url(r'^sendgrid_webhook/$', csrf_exempt(InboundParseWebhookView.as_view()), name='inbound_event_webhook_callback'), - url(r'^issue/comment/(?P\d+)/$',comments.views.AddComment, name='add_comment'), + 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/(?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 eb5ffc15e..7266f80cc 100644 --- a/comments/views.py +++ b/comments/views.py @@ -6,9 +6,10 @@ from django.shortcuts import render, get_object_or_404 import os -@login_required(login_url="/accounts/login/") -def AddComment(request,pk): - issue = get_object_or_404(Issue,pk=pk) +@login_required(login_url='/accounts/login/') +def add_comment(request): + pass + issue = Issue.objects.get(pk=request.POST.get('issue_pk')) if request.method == "POST": author = request.user.username author_url = os.path.join('/profile/',request.user.username) @@ -16,7 +17,10 @@ def AddComment(request,pk): text=request.POST.get('text_comment') comment =Comment(author=author, author_url=author_url, issue=issue, text=text) comment.save() - return HttpResponseRedirect(os.path.join('/issue',str(pk))) + all_comment = Comment.objects.filter(issue=issue) + return render(request,'comments.html',{'all_comment':all_comment, + 'user':request.user},) + @login_required(login_url="/accounts/login/") def DeleteComment(request,pk): diff --git a/website/templates/issue.html b/website/templates/issue.html index 4c74817c5..da7cc5b8d 100644 --- a/website/templates/issue.html +++ b/website/templates/issue.html @@ -187,9 +187,9 @@

OCR Results:


-{% if all_comment %} -

Comments:

+

Comments:

+
{% for comment in all_comment %}
@@ -207,13 +207,37 @@

Comments:

{% empty %} {% endfor %} -{% endif %} -
+
+ {% csrf_token %}
- + + +
- + + + + + {% endblock %} From 227701fdd113cf9acb50b2e557ceb9241283d236 Mon Sep 17 00:00:00 2001 From: Mohit Anand Date: Sun, 9 Jul 2017 07:15:14 +0530 Subject: [PATCH 2/2] Added comments.html --- website/templates/comments.html | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 website/templates/comments.html diff --git a/website/templates/comments.html b/website/templates/comments.html new file mode 100644 index 000000000..98b824efe --- /dev/null +++ b/website/templates/comments.html @@ -0,0 +1,20 @@ +
+{% for comment in all_comment %} +
+
+
+ {{ comment.author }} +  commented on 
{{ comment.created_date }}
+ {% if user.username == comment.author %} + Edit + Delete + {% endif %} +
+
+

{{ comment.text|linebreaks }}

+
+
+{% empty %} +{% endfor %} + +
\ No newline at end of file