summaryrefslogtreecommitdiff
path: root/commentingapp/views.py
diff options
context:
space:
mode:
authorankitjavalkar2016-04-21 15:17:07 +0530
committerankitjavalkar2016-04-21 15:17:07 +0530
commit227a5d9ea190d895e788108bda77316b6b6b867a (patch)
treea6bd0fcc7e06df44046e08e6c7c29f8860e462a3 /commentingapp/views.py
parent5d4ee0860bc6c92f845624bca2a8d515c96c4a30 (diff)
parenteb79ae5bb0d6525d812b03b21b2085a796c4567a (diff)
downloadPython-TBC-Interface-227a5d9ea190d895e788108bda77316b6b6b867a.tar.gz
Python-TBC-Interface-227a5d9ea190d895e788108bda77316b6b6b867a.tar.bz2
Python-TBC-Interface-227a5d9ea190d895e788108bda77316b6b6b867a.zip
Merge pull request #28 from maheshgudi/master
added admin tools link
Diffstat (limited to 'commentingapp/views.py')
-rw-r--r--commentingapp/views.py52
1 files changed, 29 insertions, 23 deletions
diff --git a/commentingapp/views.py b/commentingapp/views.py
index b4c2b84..f2a0f36 100644
--- a/commentingapp/views.py
+++ b/commentingapp/views.py
@@ -4,37 +4,43 @@ from django.template import RequestContext
from .models import Url, Comments
from django.contrib.auth.decorators import user_passes_test
from django.db.models import Q
-from tbc.models import Book, Chapters
from django.contrib.auth.models import User
from collections import Counter
import os.path
from email.mime.text import MIMEText
+from django.http import Http404
+from tbc.models import Book, Chapters
+from tbc.views import is_reviewer
@user_passes_test(lambda u:u.is_superuser, login_url="/admin/login/")
-def commenting(req):
- ci = RequestContext(req)
- url_instance = Url.objects.filter(Q(comments__is_notified = 0)).distinct()
- context = {"url_context": url_instance, "user": req.user}
+def commenting(request):
+ ci = RequestContext(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, "user": curr_user}
- if req.method == "POST":
- notified_comment_list = req.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)
+ 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 couldnot be sent"}
- return render_to_response("notified.html", context, ci)
+ 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 couldnot be sent"}
+ return render_to_response("notified.html", context, ci)
- return render_to_response ("commenting.html", context, ci)
+ return render_to_response ("commenting.html", context, ci)