blob: 80f37e82eecb2c848c1bea00176d0622db63e7d3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
from django.shortcuts import render, render_to_response
from django.contrib.auth.decorators import login_required
from django.template.context_processors import csrf
from .models import Url, Comments
from django.db.models import Q
from collections import Counter
from django.http import Http404
from tbc.models import Book, Chapters
from tbc.views import is_reviewer
@login_required(login_url="/login/")
def commenting(request):
context = {}
context.update(csrf(request))
curr_user = request.user
if not is_reviewer(curr_user):
raise Http404("You are not allowed to view this page")
else:
url_instance = Url.objects.filter(Q(comments__is_notified = 0)).distinct()
context["url_context"] = url_instance
context["reviewer"] = curr_user
if request.method == "POST":
notified_comment_list = request.POST.getlist("comment")
url_list = []
for notified_comments in notified_comment_list:
url_comment_list= notified_comments.split(", ")
url_list.append(url_comment_list[0])
Comments.objects.filter(comments = url_comment_list[1]).update(is_notified = 1)
counter = Counter(url_list)
url_db_instance = Url()
contributor_details = url_db_instance.get_contributor_details(counter)
status = url_db_instance.send_mail_to_contributor(contributor_details)
if status == True:
context["notified_comments"] = "You have suceesfully notified the contributors"
else:
context["notified_comments"] = "Mail could not be sent"
return render_to_response("notified.html", context)
return render_to_response ("commenting.html", context)
|