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

Simple Comments section on the issues page #191

Merged
merged 32 commits into from
Jun 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
4db18fc
Updated urls
mohitanand001 Jun 5, 2017
e721646
Added forms and Updated views
mohitanand001 Jun 5, 2017
e3c5e09
Modified issue.html
mohitanand001 Jun 5, 2017
7be2ddf
Update views.py
mohitanand001 Jun 5, 2017
5aba3ae
Updating the migrations files
mohitanand001 Jun 5, 2017
79d8bcb
Added migration files
mohitanand001 Jun 5, 2017
61a6226
Delete 0001_initial.pyc
mohitanand001 Jun 5, 2017
2935886
Delete 0002_auto_20160828_0116.pyc
mohitanand001 Jun 5, 2017
db22fd0
Delete 0003_auto_20160831_2326.pyc
mohitanand001 Jun 5, 2017
3e59e18
Delete 0004_auto_20160903_2344.pyc
mohitanand001 Jun 5, 2017
c715c09
Delete 0005_auto_20160909_1902.pyc
mohitanand001 Jun 5, 2017
cd76ddd
Delete 0006_auto_20160920_1713.pyc
mohitanand001 Jun 5, 2017
4310f83
Delete 0007_auto_20160920_1714.pyc
mohitanand001 Jun 5, 2017
d7b65b2
Delete 0008_auto_20160920_1715.pyc
mohitanand001 Jun 5, 2017
89bf8b5
Delete 0009_issue_domain.pyc
mohitanand001 Jun 5, 2017
b9eb964
Delete 0010_auto_20160930_0317.pyc
mohitanand001 Jun 5, 2017
09281d1
Delete 0011_auto_20161105_1428.pyc
mohitanand001 Jun 5, 2017
945237f
Delete 0012_auto_20161105_1430.pyc
mohitanand001 Jun 5, 2017
7b10fd1
Delete 0013_auto_20161113_1352.pyc
mohitanand001 Jun 5, 2017
bbb79d6
Delete 0014_auto_20161113_1417.pyc
mohitanand001 Jun 5, 2017
242fe75
Delete 0015_domain_github.pyc
mohitanand001 Jun 5, 2017
624c870
Delete 0016_hunt_txn_id.pyc
mohitanand001 Jun 5, 2017
35ba92e
Delete 0017_issue_ocr.pyc
mohitanand001 Jun 5, 2017
22ec0a6
Delete 0018_domain_email_event.pyc
mohitanand001 Jun 5, 2017
8c5d5cd
Delete 0019_issue_status.pyc
mohitanand001 Jun 5, 2017
0fa244c
Delete 0020_issue_user_agent.pyc
mohitanand001 Jun 5, 2017
42f5f36
Delete 0021_issue_views.pyc
mohitanand001 Jun 5, 2017
9355994
Delete 0022_auto_20161212_1510.pyc
mohitanand001 Jun 5, 2017
1465088
Delete 0023_invitefriend.pyc
mohitanand001 Jun 5, 2017
92dd66b
Delete 0025_auto_20170605_1909.pyc
mohitanand001 Jun 5, 2017
3a427d4
Delete __init__.pyc
mohitanand001 Jun 5, 2017
3bf3924
Delete 0024_userprofile.pyc
mohitanand001 Jun 5, 2017
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
1 change: 1 addition & 0 deletions bugheist/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
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'^post/(?P<pk>\d+)/comment/$',website.views.add_comment_to_post, name='add_comment_to_post'),

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

9 changes: 8 additions & 1 deletion website/forms.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django import forms
from .models import Issue, InviteFriend, UserProfile
from .models import Issue, InviteFriend, UserProfile, Comment


class IssueEditForm(forms.ModelForm):
Expand All @@ -24,3 +24,10 @@ class UserProfileForm(forms.ModelForm):
class Meta:
model = UserProfile
fields = ('user_avatar',)


class CommentForm(forms.ModelForm):

class Meta:
model = Comment
fields = ('text',)
35 changes: 35 additions & 0 deletions website/migrations/0025_auto_20170605_1909.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.2 on 2017-06-05 19:09
from __future__ import unicode_literals

from django.db import migrations, models
import django.db.models.deletion
import django.utils.timezone
import website.models


class Migration(migrations.Migration):

dependencies = [
('website', '0024_userprofile'),
]

operations = [
migrations.CreateModel(
name='Comment',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('author', models.CharField(max_length=200)),
('author_url', models.CharField(max_length=200)),
('text', models.TextField()),
('created_date', models.DateTimeField(default=django.utils.timezone.now)),
('approved_comment', models.BooleanField(default=False)),
('post', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='comments', to='website.Issue')),
],
),
migrations.AlterField(
model_name='userprofile',
name='user_avatar',
field=models.ImageField(blank=True, null=True, upload_to=website.models.user_images_path),
),
]
19 changes: 19 additions & 0 deletions website/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from PIL import Image
from django.db.models import Count
from colorthief import ColorThief
from django.utils import timezone


class Domain(models.Model):
Expand Down Expand Up @@ -307,3 +308,21 @@ def create_profile(sender, **kwargs):
profile.save()

post_save.connect(create_profile, sender=User)


class Comment(models.Model):
post = models.ForeignKey('Issue', related_name='comments')
author = models.CharField(max_length=200)
author_url = models.CharField(max_length=200)
text = models.TextField()
created_date = models.DateTimeField(default=timezone.now)
approved_comment = models.BooleanField(default=False)

def approve(self):
self.approved_comment = True
self.save()

def __str__(self):
return self.text


7 changes: 7 additions & 0 deletions website/templates/add_comment_to_post.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{% block content %}
<h1>New comment</h1>
<form method="POST" class="post-form">{% csrf_token %}
{{ form.as_p }}
<button type="submit" class="save btn btn-default">Send</button>
</form>
{% endblock %}
16 changes: 16 additions & 0 deletions website/templates/issue.html
Original file line number Diff line number Diff line change
Expand Up @@ -209,4 +209,20 @@ <h2 class="page-header"> {{object.description}} <span class="pull-right"><i clas
<hr>
</div>
</div>

<h3>Comments</h3>

{% for comment in all_comment %}
<hr>
<div class="comment">
<div class="date">{{ comment.created_date }}</div>
<strong><a href="{{ comment.author_url }}">{{ comment.author }}</a></strong>
<p>{{ comment.text|linebreaks }}</p>
</div>
{% empty %}
<p>Be the first to comment.</p>
{% endfor %}
<a class="btn btn-default" href="{% url 'add_comment_to_post' pk=issue.pk %}">Add comment</a>


{% endblock %}
17 changes: 16 additions & 1 deletion website/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
import os
import json
from user_agents import parse
from .forms import IssueEditForm, FormInviteFriend, UserProfileForm
from .forms import IssueEditForm, FormInviteFriend, UserProfileForm, CommentForm
import random
from django.contrib.auth.decorators import login_required
from django.utils.decorators import method_decorator
Expand Down Expand Up @@ -434,6 +434,7 @@ def get_context_data(self, **kwargs):
context['os_version'] = user_agent.os.version_string
context['users_score'] = Points.objects.filter(user=self.object.user).aggregate(total_score=Sum('score')).values()[0]
context['issue_count'] = Issue.objects.filter(url__contains=self.object.domain_name).count()
context['all_comment'] = self.object.comments.all
return context


Expand Down Expand Up @@ -644,3 +645,17 @@ def form_valid(self, form):
return HttpResponseRedirect(self.success_url)


def add_comment_to_post(request, pk):
post = get_object_or_404(Issue, pk=pk)
if request.method == "POST":
form = CommentForm(request.POST)
if form.is_valid():
comment = form.save(commit=False)
comment.author = request.user.username
comment.author_url = os.path.join('/profile/',request.user.username)
comment.post = post
comment.save()
return redirect(os.path.join('/issue',str(pk)))
else:
form = CommentForm()
return render(request, 'add_comment_to_post.html', {'form': form})