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

Added comments.html #325

Merged
merged 2 commits into from
Jul 9, 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: 3 additions & 1 deletion bugheist/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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<pk>\d+)/$',comments.views.AddComment, name='add_comment'),
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/(?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)
12 changes: 8 additions & 4 deletions comments/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,21 @@
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)
issue = issue
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):
Expand Down
20 changes: 20 additions & 0 deletions website/templates/comments.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<div class="comment_group" >
{% for comment in all_comment %}
<hr>
<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>
<p>{{ comment.text|linebreaks }}</p>
</div>
</div>
{% empty %}
{% endfor %}

</div>
36 changes: 30 additions & 6 deletions website/templates/issue.html
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,9 @@ <h4>OCR Results:</h4><hr>
</div>


{% if all_comment %}
<h3>Comments:</h3>

<h3>Comments:</h3>
<div id="target_div">
{% for comment in all_comment %}
<hr>
<div class="well comment">
Expand All @@ -207,13 +207,37 @@ <h3>Comments:</h3>
</div>
{% empty %}
{% endfor %}
{% endif %}
<form method="post" action="{% url 'comments.views.AddComment' pk=issue.pk %}" id="comments">
</div>
<form id="comments">
{% csrf_token %}
<div class="form-group">
<textarea placeholder="Comment" class="form-control" name="text_comment" required></textarea>
<input type="hidden" name="issue_pk" id="issue_pk" value="{{ issue.pk }}" >
<textarea placeholder="Comment" class="form-control" id="text_comment" name="text_comment" required></textarea>

</div>
<button class="btn btn-small" type="submit">Add Comment</button>
<button id="comment_submit" class="btn btn-small" type="submit">Add Comment</button>
</form>


<script type="text/javascript">
$(document).on('submit','#comments',function(e){
e.preventDefault();

$.ajax({
type: 'POST',
url: '/issue/comment/add/',
data:{
text_comment: $('#text_comment').val(),
issue_pk: $('#issue_pk').val(),
csrfmiddlewaretoken: $('input[name=csrfmiddlewaretoken]').val(),
},
success: function(data){
$('#target_div').html(data);
}

});
});
</script>


{% endblock %}