From f60d22247606b536227f9dc9a3d58d2a2919665d Mon Sep 17 00:00:00 2001 From: mahesh Date: Thu, 21 Apr 2016 17:23:38 +0530 Subject: added login_required decorator --- commentingapp/views.py | 6 +----- tbc/views.py | 2 +- tbc_error_page/views.py | 8 +++----- 3 files changed, 5 insertions(+), 11 deletions(-) diff --git a/commentingapp/views.py b/commentingapp/views.py index f2a0f36..a97fc07 100644 --- a/commentingapp/views.py +++ b/commentingapp/views.py @@ -2,17 +2,13 @@ from django.shortcuts import render, render_to_response from django.contrib.auth.decorators import login_required 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 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/") +@login_required(login_url="/login/") def commenting(request): ci = RequestContext(request) diff --git a/tbc/views.py b/tbc/views.py index 18e2d4d..1466ff1 100755 --- a/tbc/views.py +++ b/tbc/views.py @@ -1415,7 +1415,7 @@ def link_image(request): context['success'] = True return render_to_response('tbc/link_image.html', context, context_instance=ci) -@login_required( login_url= "/admin") +@login_required(login_url="/login/") def admin_tools(request): ci = RequestContext(request) curr_user = request.user diff --git a/tbc_error_page/views.py b/tbc_error_page/views.py index 099f996..3d87454 100644 --- a/tbc_error_page/views.py +++ b/tbc_error_page/views.py @@ -1,14 +1,12 @@ from django.shortcuts import render_to_response from .models import Error, Broken, get_json_from_file -from django.contrib.auth.decorators import user_passes_test +from django.contrib.auth.decorators import login_required from django.template import RequestContext from django.http import Http404 -import json -import os from tbc.views import is_reviewer -@user_passes_test(lambda u:u.is_superuser, login_url="/admin/login") +@login_required(login_url="/login/") def error(request): ci = RequestContext(request) curr_user = request.user @@ -38,7 +36,7 @@ def error(request): context = {"context": error_details, "user": curr_user} return render_to_response ("error.html", context, ci) -@user_passes_test(lambda u:u.is_superuser, login_url="/admin/login") +@login_required(login_url="/login/") def broken(request): ci = RequestContext(request) curr_user = request.user -- cgit From 1d6eede612130ae0bb6ea4fa03f60fc71ecbbe3d Mon Sep 17 00:00:00 2001 From: mahesh Date: Thu, 21 Apr 2016 18:34:46 +0530 Subject: changes in context --- commentingapp/views.py | 2 +- tbc/views.py | 4 ++-- tbc_error_page/views.py | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/commentingapp/views.py b/commentingapp/views.py index a97fc07..22bf0e0 100644 --- a/commentingapp/views.py +++ b/commentingapp/views.py @@ -17,7 +17,7 @@ def commenting(request): 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} + context = {"url_context": url_instance, "reviewer": curr_user} if request.method == "POST": notified_comment_list = request.POST.getlist("comment") diff --git a/tbc/views.py b/tbc/views.py index 1466ff1..f6e93ae 100755 --- a/tbc/views.py +++ b/tbc/views.py @@ -1423,5 +1423,5 @@ def admin_tools(request): if not is_reviewer(curr_user): raise Http404("You are not allowed to view this page") else: - context = {"user":curr_user} - return render_to_response('tbc/admin-tools.html', context, context_instance=ci) + context = {"reviewer":curr_user} + return render_to_response('tbc/admin-tools.html', context, ci) diff --git a/tbc_error_page/views.py b/tbc_error_page/views.py index 3d87454..6dd5206 100644 --- a/tbc_error_page/views.py +++ b/tbc_error_page/views.py @@ -28,12 +28,12 @@ def error(request): deliberate_urls_list = request.POST.getlist("deliberate") db_instance.update_deliberate_error(deliberate_urls_list) - context = {"user":request.user, "deliberate" :deliberate_urls_list} + context = {"reviewer":request.user, "deliberate" :deliberate_urls_list} return render_to_response ("deliberate.html", context, ci) - context = {"context": error_details, "user": curr_user} + context = {"context": error_details, "reviewer": curr_user} return render_to_response ("error.html", context, ci) @login_required(login_url="/login/") @@ -54,7 +54,7 @@ def broken(request): db_instance.update_broken_data(broken_json_data) broken = Broken.objects.all() - context = {"broken": broken, "user": curr_user} + context = {"broken": broken, "reviewer": curr_user} return render_to_response("broken.html", context, ci) -- cgit From e85df2bdab22c5ca8364683d8839148ff1f3a45d Mon Sep 17 00:00:00 2001 From: mahesh Date: Tue, 26 Apr 2016 14:57:18 +0530 Subject: made changes to convert notebook function --- tbc/views.py | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/tbc/views.py b/tbc/views.py index f6e93ae..e866c46 100755 --- a/tbc/views.py +++ b/tbc/views.py @@ -1189,7 +1189,6 @@ def BrowseBooks(request): return render_to_response('tbc/browse-books.html', context) - def ConvertNotebook(request, notebook_path=None): """ Checks for the modified time of ipython notebooks and corresponding html page and replaces html page with new one if corresponding ipython notebook has been modified. """ @@ -1198,16 +1197,23 @@ def ConvertNotebook(request, notebook_path=None): path = os.path.join(local.path, notebook_path.strip(".ipynb")) template_html = path+".html" template_ipynb =path+".ipynb" - modified_time_for_html = os.stat(template_html).st_mtime - modified_time_for_ipynb = os.stat(template_ipynb).st_mtime + template_dir = os.path.dirname(path) + + def nbconvert(template_ipynb): + notebook_convert = "ipython nbconvert --to html {0} --FilesWriter.build_directory={1}".format(template_ipynb, template_dir) + subprocess.call (notebook_convert, shell = True) - if os.path.isfile(template_html) and modified_time_for_html > modified_time_for_ipynb: - return render_to_response(template_html, {}) - else: - notebook_convert = "ipython nbconvert --to html %s" % str(template_ipynb) - subprocess.call (notebook_convert) - return render_to_response(template_html, {}) + if os.path.isfile(template_html): + modified_time_for_html = os.stat(template_html).st_mtime + modified_time_for_ipynb = os.stat(template_ipynb).st_mtime + if not modified_time_for_html > modified_time_for_ipynb: + nbconvert(template_ipynb) + + else: + nbconvert(template_ipynb) + + return render_to_response(template_html, context) def CompletedBooks(request): -- cgit From 9219d098a7abc0335a57a3eacd74368433e440da Mon Sep 17 00:00:00 2001 From: mahesh Date: Tue, 26 Apr 2016 15:29:34 +0530 Subject: minor changes in displaying user full name --- commentingapp/templates/commenting.html | 2 +- tbc_error_page/templates/broken.html | 2 +- tbc_error_page/templates/error.html | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/commentingapp/templates/commenting.html b/commentingapp/templates/commenting.html index 3e888e6..82c19ed 100644 --- a/commentingapp/templates/commenting.html +++ b/commentingapp/templates/commenting.html @@ -4,7 +4,7 @@ {% block content %}

TBC Commenting

-
Hi {{user}}

+
Hi {{reviewer.get_full_name}}

Go to Disqus admin Page {% if not url_context %} diff --git a/tbc_error_page/templates/broken.html b/tbc_error_page/templates/broken.html index 841069c..9c49785 100644 --- a/tbc_error_page/templates/broken.html +++ b/tbc_error_page/templates/broken.html @@ -5,7 +5,7 @@

There are no new comments

{% else %}

TBC Broken Links Page

-
Hi {{user}}
+
Hi {{reviewer.get_full_name}}
TBC Error Status Page

diff --git a/tbc_error_page/templates/error.html b/tbc_error_page/templates/error.html index 237c7f3..057820e 100644 --- a/tbc_error_page/templates/error.html +++ b/tbc_error_page/templates/error.html @@ -6,8 +6,8 @@ {% block content %} -

TBC Error Page

-
Hi {{ user }}
+

TBC Error Page

+
Hi {{reviewer.get_full_name}}

TBC Broken Links page

{% if not context %}

There are no new errors

-- cgit From a1018449fb6e6d584a8b86f07c6642ce852c4a19 Mon Sep 17 00:00:00 2001 From: mahesh Date: Tue, 26 Apr 2016 15:30:21 +0530 Subject: removed request context --- commentingapp/views.py | 17 ++++++++++------- tbc_error_page/views.py | 24 ++++++++++++++---------- 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/commentingapp/views.py b/commentingapp/views.py index 22bf0e0..66606b7 100644 --- a/commentingapp/views.py +++ b/commentingapp/views.py @@ -1,6 +1,6 @@ from django.shortcuts import render, render_to_response from django.contrib.auth.decorators import login_required -from django.template import RequestContext +from django.core.context_processors import csrf from .models import Url, Comments from django.db.models import Q from collections import Counter @@ -8,16 +8,19 @@ 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): - ci = RequestContext(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, "reviewer": curr_user} + context["url_context"] = url_instance + context["reviewer"] = curr_user if request.method == "POST": notified_comment_list = request.POST.getlist("comment") @@ -33,10 +36,10 @@ def commenting(request): status = url_db_instance.send_mail_to_contributor(contributor_details) if status == True: - context = {"notified_comments": "You have suceesfully notified the contributors"} + 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) + context["notified_comments"] = "Mail could not be sent" + return render_to_response("notified.html", context) - return render_to_response ("commenting.html", context, ci) + return render_to_response ("commenting.html", context) diff --git a/tbc_error_page/views.py b/tbc_error_page/views.py index 6dd5206..d788afa 100644 --- a/tbc_error_page/views.py +++ b/tbc_error_page/views.py @@ -1,14 +1,15 @@ from django.shortcuts import render_to_response from .models import Error, Broken, get_json_from_file from django.contrib.auth.decorators import login_required -from django.template import RequestContext +from django.core.context_processors import csrf from django.http import Http404 from tbc.views import is_reviewer @login_required(login_url="/login/") def error(request): - ci = RequestContext(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") @@ -28,17 +29,19 @@ def error(request): deliberate_urls_list = request.POST.getlist("deliberate") db_instance.update_deliberate_error(deliberate_urls_list) - context = {"reviewer":request.user, "deliberate" :deliberate_urls_list} + context["reviewer"] = request.user + context["deliberate"] = deliberate_urls_list - return render_to_response ("deliberate.html", context, ci) + return render_to_response ("deliberate.html", context) - - context = {"context": error_details, "reviewer": curr_user} - return render_to_response ("error.html", context, ci) + context["context"] = error_details + context[ "reviewer"] = curr_user + return render_to_response ("error.html", context) @login_required(login_url="/login/") def broken(request): - ci = RequestContext(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") @@ -54,7 +57,8 @@ def broken(request): db_instance.update_broken_data(broken_json_data) broken = Broken.objects.all() - context = {"broken": broken, "reviewer": curr_user} - return render_to_response("broken.html", context, ci) + context["broken"] = broken + context[ "reviewer"] = curr_user + return render_to_response("broken.html", context) -- cgit