From 54bd70b5d4338f9d2737c4403352ce45c111216e Mon Sep 17 00:00:00 2001
From: holyantony
Date: Mon, 23 Mar 2015 11:46:11 +0530
Subject: Subject:Added validation for comments
Description:
1. Check for blank field
---
static/website/css/main.css | 6 +--
website/forms.py | 4 ++
website/models.py | 2 +-
website/views.py | 126 ++++++++++++++++++++++++--------------------
4 files changed, 76 insertions(+), 62 deletions(-)
diff --git a/static/website/css/main.css b/static/website/css/main.css
index 6715f8b..fc96f5b 100644
--- a/static/website/css/main.css
+++ b/static/website/css/main.css
@@ -228,9 +228,9 @@ table .question a{
#content .answer {
position: relative;
border-bottom: 1px solid #f5f5f5;
- padding-top: 20px;
- padding-bottom: 20px;
- margin: 10px 0px;
+
+ padding-bottom: 10px;
+ margin: 5px 0px;
}
#content .answer .body {
}
diff --git a/website/forms.py b/website/forms.py
index 6db930a..a55aec1 100644
--- a/website/forms.py
+++ b/website/forms.py
@@ -30,3 +30,7 @@ class AnswerQuesitionForm(forms.Form):
body = forms.CharField(widget=forms.Textarea(),
required = True
)
+
+class AnswerCommentForm(forms.Form):
+ body = forms.CharField(widget=forms.Textarea(),required = True)
+
diff --git a/website/models.py b/website/models.py
index 0e11a4c..28f251d 100644
--- a/website/models.py
+++ b/website/models.py
@@ -66,7 +66,7 @@ class AnswerVote(models.Model):
class AnswerComment(models.Model):
uid = models.IntegerField()
answer = models.ForeignKey(Answer)
- body = models.TextField()
+ body = models.TextField(blank=False)
date_created = models.DateTimeField(auto_now_add=True)
date_modified = models.DateTimeField(auto_now=True)
diff --git a/website/views.py b/website/views.py
index 542f688..de3e370 100644
--- a/website/views.py
+++ b/website/views.py
@@ -14,7 +14,7 @@ User = get_user_model()
from website.models import Question, Answer, Notification, AnswerComment, FossCategory
from spoken_auth.models import TutorialDetails, TutorialResources
-from website.forms import NewQuestionForm, AnswerQuesitionForm
+from website.forms import NewQuestionForm, AnswerQuesitionForm,AnswerCommentForm
from website.helpers import get_video_info, prettify
from django.db.models import Count
@@ -132,64 +132,74 @@ def answer_comment(request):
answer_id = request.POST['answer_id'];
body = request.POST['body']
answer = Answer.objects.get(pk=answer_id)
- comment = AnswerComment()
- comment.uid = request.user.id
- comment.answer = answer
- comment.body = body.encode('unicode_escape')
- comment.save()
+ form = AnswerCommentForm(request.POST)
+ if form.is_valid():
+ comment = AnswerComment()
+ comment.uid = request.user.id
+ comment.answer = answer
+ comment.body = body.encode('unicode_escape')
+ comment.save()
+
+ # notifying the answer owner
+ if answer.uid != request.user.id:
+ notification = Notification()
+ notification.uid = answer.uid
+ notification.pid = request.user.id
+ notification.qid = answer.question.id
+ notification.aid = answer.id
+ notification.cid = comment.id
+ notification.save()
+
+ user = User.objects.get(id=answer.uid)
+ subject = 'Comment for your answer'
+ message = """
+ Dear {0}
+ A comment has been posted on your answer.
+ Link: {1}
+ Regards,
+ Spoken Tutorial Forums
+ """.format(
+ user.username,
+ "http://forums.spoken-tutorial.org/question/" + str(answer.question.id) + "#answer" + str(answer.id)
+ )
+ forums_mail(user.email, subject, message)
+
+ # notifying other users in the comment thread
+ uids = answer.answercomment_set.filter(answer=answer).values_list('uid', flat=True)
+ #getting distinct uids
+ uids = set(uids)
+ uids.remove(request.user.id)
+ for uid in uids:
+ notification = Notification()
+ notification.uid = uid
+ notification.pid = request.user.id
+ notification.qid = answer.question.id
+ notification.aid = answer.id
+ notification.cid = comment.id
+ notification.save()
+
+ user = User.objects.get(id=uid)
+ subject = 'Comment has a reply'
+ message = """
+ Dear {0}
+ A reply has been posted on your comment.
+ Link: {1}
+ Regards,
+ Spoken Tutorial Forums
+ """.format(
+ user.username,
+ "http://forums.spoken-tutorial.org/question/" + str(answer.question.id) + "#answer" + str(answer.id)
+ )
+ forums_mail(user.email, subject, message)
+
+ else:
+ print "not valid"
- # notifying the answer owner
- if answer.uid != request.user.id:
- notification = Notification()
- notification.uid = answer.uid
- notification.pid = request.user.id
- notification.qid = answer.question.id
- notification.aid = answer.id
- notification.cid = comment.id
- notification.save()
-
- user = User.objects.get(id=answer.uid)
- subject = 'Comment for your answer'
- message = """
- Dear {0}
- A comment has been posted on your answer.
- Link: {1}
- Regards,
- Spoken Tutorial Forums
- """.format(
- user.username,
- "http://forums.spoken-tutorial.org/question/" + str(answer.question.id) + "#answer" + str(answer.id)
- )
- forums_mail(user.email, subject, message)
-
- # notifying other users in the comment thread
- uids = answer.answercomment_set.filter(answer=answer).values_list('uid', flat=True)
- #getting distinct uids
- uids = set(uids)
- uids.remove(request.user.id)
- for uid in uids:
- notification = Notification()
- notification.uid = uid
- notification.pid = request.user.id
- notification.qid = answer.question.id
- notification.aid = answer.id
- notification.cid = comment.id
- notification.save()
-
- user = User.objects.get(id=uid)
- subject = 'Comment has a reply'
- message = """
- Dear {0}
- A reply has been posted on your comment.
- Link: {1}
- Regards,
- Spoken Tutorial Forums
- """.format(
- user.username,
- "http://forums.spoken-tutorial.org/question/" + str(answer.question.id) + "#answer" + str(answer.id)
- )
- forums_mail(user.email, subject, message)
- return HttpResponseRedirect("/question/" + str(answer.question.id) + "#")
+ form = AnswerCommentForm()
+ print form
+
+
+ return HttpResponseRedirect("/question/" + str(answer.question.id) + "#")
def filter(request, category=None, tutorial=None, minute_range=None, second_range=None):
context = {
--
cgit