summaryrefslogtreecommitdiff
path: root/tbc_error_page
diff options
context:
space:
mode:
authormahesh2016-04-21 12:37:54 +0530
committermahesh2016-04-21 12:37:54 +0530
commiteb79ae5bb0d6525d812b03b21b2085a796c4567a (patch)
treea6bd0fcc7e06df44046e08e6c7c29f8860e462a3 /tbc_error_page
parent07e09287fbc0d2fd4f792bba71bf39414a25e4b5 (diff)
downloadPython-TBC-Interface-eb79ae5bb0d6525d812b03b21b2085a796c4567a.tar.gz
Python-TBC-Interface-eb79ae5bb0d6525d812b03b21b2085a796c4567a.tar.bz2
Python-TBC-Interface-eb79ae5bb0d6525d812b03b21b2085a796c4567a.zip
added Http404 for error and broken pages
Diffstat (limited to 'tbc_error_page')
-rw-r--r--tbc_error_page/views.py76
1 files changed, 41 insertions, 35 deletions
diff --git a/tbc_error_page/views.py b/tbc_error_page/views.py
index aa32453..099f996 100644
--- a/tbc_error_page/views.py
+++ b/tbc_error_page/views.py
@@ -2,55 +2,61 @@ 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.template import RequestContext
+from django.http import Http404
import json
import os
+from tbc.views import is_reviewer
-#@login_required(login_url="/admin/login/")
@user_passes_test(lambda u:u.is_superuser, login_url="/admin/login")
-
-
-
-def error(req):
- ci = RequestContext(req)
- db_instance = Error()
- error_json_data = get_json_from_file("error.pickle")
-
- if not Error.objects.exists():
- db_instance.create_new_error_data(error_json_data)
+def error(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:
- db_instance.delete_redundant_error_data(error_json_data)
- db_instance.update_error_data(error_json_data)
+ db_instance = Error()
+ error_json_data = get_json_from_file("error.pickle")
- error_details = Error.objects.filter(is_deliberate = 0)
+ if not Error.objects.exists():
+ db_instance.create_new_error_data(error_json_data)
+ else:
+ db_instance.delete_redundant_error_data(error_json_data)
+ db_instance.update_error_data(error_json_data)
- if req.method == "POST":
- deliberate_urls_list = req.POST.getlist("deliberate")
- db_instance.update_deliberate_error(deliberate_urls_list)
+ error_details = Error.objects.filter(is_deliberate = 0)
- context = {"user":req.user, "deliberate" :deliberate_urls_list}
-
- return render_to_response ("deliberate.html", context, ci)
+ if request.method == "POST":
+ deliberate_urls_list = request.POST.getlist("deliberate")
+ db_instance.update_deliberate_error(deliberate_urls_list)
+ context = {"user":request.user, "deliberate" :deliberate_urls_list}
+
+ return render_to_response ("deliberate.html", context, ci)
- context = {"context": error_details, "user": req.user}
- return render_to_response ("error.html", context, ci)
-
-def broken(req):
- ci = RequestContext(req)
- db_instance = Broken()
- broken_json_data = get_json_from_file("broken.pickle")
-
- if not Broken.objects.exists():
- db_instance.create_new_broken_data(broken_json_data)
+ 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")
+def broken(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:
- db_instance.delete_redundant_broken_data(broken_json_data)
- db_instance.update_broken_data(broken_json_data)
+ db_instance = Broken()
+ broken_json_data = get_json_from_file("broken.pickle")
- broken = Broken.objects.all()
- context = {"broken": broken, "user": req.user}
- return render_to_response("broken.html", context, ci)
+ if not Broken.objects.exists():
+ db_instance.create_new_broken_data(broken_json_data)
+
+ else:
+ db_instance.delete_redundant_broken_data(broken_json_data)
+ db_instance.update_broken_data(broken_json_data)
+
+ broken = Broken.objects.all()
+ context = {"broken": broken, "user": curr_user}
+ return render_to_response("broken.html", context, ci)