Skip to content

Commit

Permalink
Merge pull request #263 from jajodiaraghav/patch_1
Browse files Browse the repository at this point in the history
Comment widget
  • Loading branch information
jajodiaraghav authored Jun 9, 2017
2 parents c028d71 + 40798fa commit 39be5b9
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 68 deletions.
8 changes: 4 additions & 4 deletions bugheist/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@
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/(?P<pk>\d+)/commentadd/$',comments.views.AddComment, name='add_comment'),
url(r'^issue/(?P<pk>\d+)/commenteditpage/$',comments.views.EditCommentPage, name='edit_commentpage'),
url(r'^issue/(?P<pk>\d+)/commentedit/$',comments.views.EditComment, name='edit_comment'),
url(r'^issue/(?P<pk>\d+)/commentdel/$',comments.views.DeleteComment, name='delete_comment'),
url(r'^issue/comment/(?P<pk>\d+)/$',comments.views.AddComment, name='add_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'),

) + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

10 changes: 0 additions & 10 deletions comments/editp.html

This file was deleted.

27 changes: 5 additions & 22 deletions comments/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@
from website.models import Issue,UserProfile
from django.shortcuts import render, get_object_or_404
import os
# Create your views here.




@login_required(login_url="/accounts/login/")
def AddComment(request,pk):
Expand All @@ -18,27 +14,17 @@ def AddComment(request,pk):
author_url = os.path.join('/profile/',request.user.username)
issue = issue
text=request.POST.get('text_comment')
comment =Comment(
author=author,
author_url=author_url,
issue=issue,
text=text,
)
comment =Comment(author=author, author_url=author_url, issue=issue, text=text)
comment.save()
# return HttpResponse('')
return HttpResponseRedirect(os.path.join('/issue',str(pk)))

return HttpResponseRedirect(os.path.join('/issue',str(pk)))

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



return HttpResponseRedirect(os.path.join('/issue',str(comment.issue.pk)))

@login_required(login_url="/accounts/login/")
def EditComment(request,pk):
Expand All @@ -48,14 +34,11 @@ def EditComment(request,pk):
if request.method == "POST":
comment.text=request.POST.get('new_comment')
comment.save()
return HttpResponseRedirect(os.path.join('/issue',str(comment.issue.pk)))


return HttpResponseRedirect(os.path.join('/issue',str(comment.issue.pk)))

@login_required(login_url="/account/login/")
def EditCommentPage(request,pk):
comment = get_object_or_404(Comment,pk=pk)
if request.user.username!=comment.author:
return HttpResponse("Can't Edit this comment")
if request.method=="POST":
return render(request,'editp.html',{'comment':comment})
return render(request,'edit_comment.html',{'comment':comment})
11 changes: 11 additions & 0 deletions website/templates/edit_comment.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{% extends "base.html" %}

{% block content %}
<form method="post" action="{% url 'comments.views.EditComment' pk=comment.pk %}">
{% csrf_token %}
<div class="form-group">
<textarea placeholder="Comment" class="form-control" name="new_comment" required></textarea>
</div>
<button class="btn btn-small" type="submit">Update Comment</button>
</form>
{% endblock %}
15 changes: 0 additions & 15 deletions website/templates/editp.html

This file was deleted.

33 changes: 16 additions & 17 deletions website/templates/issue.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@
.fb-xfbml-parse-ignore {
margin-top: -12px;
}
.comment .comment-actions {
display: inline-flex;
}
.comment .comment-actions .btn {
margin-left: 10px;
}
{% endblock %}
{% block content %}
<div id="fb-root"></div>
Expand Down Expand Up @@ -172,10 +178,10 @@ <h4>OCR Results:</h4><hr>
{% endif %}
</div>

<form id="comments_form" method="post" action="{% url 'comments.views.AddComment' pk=issue.pk %}">
<form method="post" action="{% url 'comments.views.AddComment' pk=issue.pk %}">
{% csrf_token %}
<div class="form-group">
<textarea placeholder="Comment" class="form-control" name="text_comment" ></textarea>
<textarea placeholder="Comment" class="form-control" name="text_comment" required></textarea>
</div>
<button class="btn btn-small" type="submit">Add Comment</button>
</form>
Expand All @@ -185,22 +191,16 @@ <h3>Comments:</h3>

{% for comment in all_comment %}
<hr>
<div class="comment">
<div style="display: inline-flex;">
<div class="date">{{ comment.created_date }}</div>
{% if user.username == comment.author %}
<form class="form-inline" id="edit_form" method="post" action="{% url 'comments.views.EditCommentPage' pk=comment.pk %}">
{% csrf_token %}
<button class="btn btn-xs btn-primary" type="submit">Edit</button>
</form>
<form class="form-inline" id="delete_form" method="post" action="{% url 'comments.views.DeleteComment' pk=comment.pk %}">
{% csrf_token %}
<button class="btn btn-xs btn-danger" type="submit">Delete</button>
</form>
<div class="well comment">
<div class="comment-actions">
<strong><a href="{{ comment.author_url }}">{{ comment.author }} </a></strong>
&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>
{% endif %}
</div>
<div>
<strong><a href="{{ comment.author_url }}">{{ comment.author }}</a></strong>
<div>
<p>{{ comment.text|linebreaks }}</p>
</div>
</div>
Expand All @@ -209,4 +209,3 @@ <h3>Comments:</h3>
{% endif %}

{% endblock %}

0 comments on commit 39be5b9

Please sign in to comment.