From fd765dab5eab149535ec01540562e8100f582307 Mon Sep 17 00:00:00 2001 From: Jayaram R Pai Date: Tue, 8 Jul 2014 08:57:48 +0530 Subject: added emails field for comment and reply --- comments/forms.py | 2 ++ comments/models.py | 2 ++ comments/templates/comments/get_comments.html | 9 +++++++-- comments/templates/comments/new_comment.html | 4 ++++ comments/templates/comments/new_reply.html | 4 ++++ comments/views.py | 2 ++ 6 files changed, 21 insertions(+), 2 deletions(-) (limited to 'comments') diff --git a/comments/forms.py b/comments/forms.py index a5fb326..b944a49 100644 --- a/comments/forms.py +++ b/comments/forms.py @@ -7,6 +7,7 @@ class CommentForm(forms.Form): page = forms.CharField(widget=forms.HiddenInput()) title = forms.CharField() body = forms.CharField(widget=forms.Textarea) + email = forms.CharField() def clean(self): cleaned_data = self.cleaned_data @@ -19,6 +20,7 @@ class CommentForm(forms.Form): class ReplyForm(forms.Form): comment_id = forms.CharField(widget=forms.HiddenInput()) body = forms.CharField(widget=forms.Textarea) + email = forms.CharField() def clean(self): return self.cleaned_data diff --git a/comments/models.py b/comments/models.py index 390b274..0c7f70f 100644 --- a/comments/models.py +++ b/comments/models.py @@ -7,12 +7,14 @@ class Comment(models.Model): chapter = models.CharField(max_length=10) example = models.CharField(max_length=10) page = models.CharField(max_length=10) + email = models.CharField(max_length=100) date_created = models.DateTimeField(auto_now_add=True) date_modified = models.DateTimeField(auto_now=True) class Reply(models.Model): comment = models.ForeignKey(Comment) body = models.CharField(max_length=200) + email = models.CharField(max_length=100) date_created = models.DateTimeField(auto_now_add=True) date_modified = models.DateTimeField(auto_now=True) diff --git a/comments/templates/comments/get_comments.html b/comments/templates/comments/get_comments.html index 5dcc84a..71443db 100644 --- a/comments/templates/comments/get_comments.html +++ b/comments/templates/comments/get_comments.html @@ -22,6 +22,7 @@
{{ comment.body }} + {{ comment.email }}
{% if comment.reply_set.all %} @@ -30,6 +31,7 @@ {% for reply in comment.reply_set.all %}

{{ reply.body }}

+ - {{ comment.email }}
{% endfor %} + Reply @@ -41,8 +43,11 @@
{% else %}
-

No comments for this example...

- Create a new comment +
+
Book: {{ book }} / Chapter: {{ chapter }} / Example: {{ example }}
+

Be the first one to create a comment for this example.

+ + Create a new comment +
{% endif %}
diff --git a/comments/templates/comments/new_comment.html b/comments/templates/comments/new_comment.html index d16aa15..64c4ab0 100644 --- a/comments/templates/comments/new_comment.html +++ b/comments/templates/comments/new_comment.html @@ -9,8 +9,12 @@ {{ form.chapter }} {{ form.example }} {{ form.page }} + {{ form.title }}
+ {{ form.body }}
+ + {{ form.email }}
Cancel diff --git a/comments/templates/comments/new_reply.html b/comments/templates/comments/new_reply.html index eac5a06..56c97f5 100644 --- a/comments/templates/comments/new_reply.html +++ b/comments/templates/comments/new_reply.html @@ -5,6 +5,7 @@
{{ comment.body }} + {{ comment.email }}
{% if comment.reply_set.all %} @@ -13,6 +14,7 @@ {% for reply in comment.reply_set.all %}

{{ reply.body }}

+ - {{ reply.email }}
{% endfor %}
@@ -23,6 +25,8 @@ {{ form.comment_id }} {{ form.body }}
+ + {{ form.email }}
Cancel diff --git a/comments/views.py b/comments/views.py index a095727..15a174b 100644 --- a/comments/views.py +++ b/comments/views.py @@ -36,6 +36,7 @@ def new_comment(request): comment.page = form.cleaned_data.get("page") comment.title = form.cleaned_data.get("title") comment.body = form.cleaned_data.get("body") + comment.email = form.cleaned_data.get("email") comment.save() return HttpResponseRedirect( '/comments/get/?book={0}&chapter={1}&example={2}&page={3}'.format( @@ -84,6 +85,7 @@ def new_reply(request): reply = Reply() reply.comment = comment reply.body = form.cleaned_data.get('body') + reply.email = form.cleaned_data.get('email') reply.save() return HttpResponseRedirect( '/comments/get/?book={0}&chapter={1}&example={2}&page={3}'.format( -- cgit