summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorashwinishinde2015-03-24 16:10:13 +0530
committerashwinishinde2015-03-24 16:10:13 +0530
commitbaae6fb32e0e2f961159297e1eb895ec7f7c77f2 (patch)
treea909b6cc45f6f34393e68782d67b90b2b57e23da
parentaf6409ed6b3c24bc865a3bc1b1ac5c73898d5485 (diff)
parentb7095e465d4b092f9119c53a7d87fb22efc2a292 (diff)
downloadFOSSEE-Forum-baae6fb32e0e2f961159297e1eb895ec7f7c77f2.tar.gz
FOSSEE-Forum-baae6fb32e0e2f961159297e1eb895ec7f7c77f2.tar.bz2
FOSSEE-Forum-baae6fb32e0e2f961159297e1eb895ec7f7c77f2.zip
Merge branch 'fossee-forum' of https://github.com/FOSSEE/spoken-tutorial-forums into fossee-forum
-rw-r--r--website/views.py145
1 files changed, 73 insertions, 72 deletions
diff --git a/website/views.py b/website/views.py
index 64c0505..c30106c 100644
--- a/website/views.py
+++ b/website/views.py
@@ -19,6 +19,7 @@ from website.forms import NewQuestionForm, AnswerQuestionForm,AnswerCommentForm
from website.helpers import get_video_info, prettify
from django.db.models import Count
+
admins = (
9, 4376, 4915, 14595, 12329, 22467, 5518, 30705
)
@@ -133,79 +134,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}<br><br>
+ A comment has been posted on your answer.<br>
+ Link: {1}<br><br>
+ Regards,<br>
+ 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}<br><br>
+ A reply has been posted on your comment.<br>
+ Link: {1}<br><br>
+ Regards,<br>
+ 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}<br><br>
- A comment has been posted on your answer.<br>
- Link: {1}<br><br>
- Regards,<br>
- 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}<br><br>
- A reply has been posted on your comment.<br>
- Link: {1}<br><br>
- Regards,<br>
- 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 = {