From b7095e465d4b092f9119c53a7d87fb22efc2a292 Mon Sep 17 00:00:00 2001
From: holyantony
Date: Tue, 24 Mar 2015 12:13:33 +0530
Subject: Subject:Modified answer_comment def in view.py
Description:
---
website/views.py | 145 ++++++++++++++++++++++++++++---------------------------
1 file changed, 73 insertions(+), 72 deletions(-)
(limited to 'website')
diff --git a/website/views.py b/website/views.py
index de3e370..366381a 100644
--- a/website/views.py
+++ b/website/views.py
@@ -18,6 +18,7 @@ from website.forms import NewQuestionForm, AnswerQuesitionForm,AnswerCommentForm
from website.helpers import get_video_info, prettify
from django.db.models import Count
+
admins = (
9, 4376, 4915, 14595, 12329, 22467, 5518, 30705
)
@@ -127,79 +128,79 @@ def question_answer(request,qid):
@login_required
def answer_comment(request):
+ if request.method == 'POST':
+ answer_id = request.POST['answer_id'];
+ print answer_id
+ answer = Answer.objects.get(pk=answer_id)
+ answers = answer.question.answer_set.all()
+ form = AnswerCommentForm(request.POST)
+ if form.is_valid():
+ body = request.POST['body']
+ print body
+ 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)
+
+ return HttpResponseRedirect("/question/" + str(answer.question.id))
+ context = {}
+ context.update(csrf(request))
+ context.update({'form':form,
+ 'question':answer.question,
+ 'answers':answers})
+ return render(request, 'website/templates/get-question.html', context)
- if request.method == 'POST':
- answer_id = request.POST['answer_id'];
- body = request.POST['body']
- answer = Answer.objects.get(pk=answer_id)
- 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"
-
- 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