Display caught errors on the page itself
Similar to the previous commit, show directly rather than redirect.
--- a/app/soc/content/assertion_error.html Thu Jun 04 22:26:24 2009 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,6 +0,0 @@
-<html>
-<head><title>Something went wrong</title></head>
-<body>
-We ran into a problem while serving your request, please try again.
-</body>
-</html>
--- a/app/soc/content/deadline_exceeded.html Thu Jun 04 22:26:24 2009 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,6 +0,0 @@
-<html>
-<head><title>We ran out of time</title></head>
-<body>
-We ran out of processing time while serving your request, please try again.
-</body>
-</html>
--- a/app/soc/content/memory_error.html Thu Jun 04 22:26:24 2009 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,6 +0,0 @@
-<html>
-<head><title>We ran out of memory</title></head>
-<body>
-We ran out of memory while serving your request, please try again.
-</body>
-</html>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/app/soc/templates/soc/assertion_error.html Thu Jun 04 23:21:33 2009 +0200
@@ -0,0 +1,6 @@
+<html>
+<head><title>Something went wrong</title></head>
+<body>
+We ran into a problem while serving your request, please try again.
+</body>
+</html>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/app/soc/templates/soc/deadline_exceeded.html Thu Jun 04 23:21:33 2009 +0200
@@ -0,0 +1,6 @@
+<html>
+<head><title>We ran out of time</title></head>
+<body>
+We ran out of processing time while serving your request, please try again.
+</body>
+</html>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/app/soc/templates/soc/memory_error.html Thu Jun 04 23:21:33 2009 +0200
@@ -0,0 +1,6 @@
+<html>
+<head><title>We ran out of memory</title></head>
+<body>
+We ran out of memory while serving your request, please try again.
+</body>
+</html>
--- a/app/soc/views/helper/decorators.py Thu Jun 04 22:26:24 2009 +0200
+++ b/app/soc/views/helper/decorators.py Thu Jun 04 23:21:33 2009 +0200
@@ -79,43 +79,36 @@
"""Decorator that insists that exceptions are handled by view.
"""
- from soc.logic.helper import timeline
- from soc.logic.models.site import logic as site_logic
- from soc.logic.models.user import logic as user_logic
from soc.views import out_of_band
- from soc.views.helper import responses
@wraps(func)
def view_wrapper(request, *args, **kwds):
"""View decorator wrapper method.
"""
- try:
- site = site_logic.getSingleton()
+ context = responses.getUniversalContext(request)
- # don't redirect admins
- redirect = not user_logic.isDeveloper()
-
- if redirect and timeline.isActivePeriod(site, 'maintenance'):
+ try:
+ if not context['is_admin'] and context['in_maintenance']:
return maintenance(request)
return func(request, *args, **kwds)
- except DeadlineExceededError, exception:
- logging.exception(exception)
- return http.HttpResponseRedirect('/soc/content/deadline_exceeded.html')
except CapabilityDisabledError, exception:
logging.exception(exception)
# assume the site is in maintenance if we get CDE
- return http.HttpResponseRedirect('/maintenance')
+ return maintenance(request)
+ except DeadlineExceededError, exception:
+ template = 'soc/deadline_exceeded.html'
except MemoryError, exception:
- logging.exception(exception)
- return http.HttpResponseRedirect('/soc/content/memory_error.html')
+ template = 'soc/memory_error.html'
except AssertionError, exception:
- logging.exception(exception)
- return http.HttpResponseRedirect('/soc/content/assertion_error.html')
+ template = 'soc/assertion_error.html'
except out_of_band.Error, error:
return responses.errorResponse(error, request)
+ logging.exception(exception)
+ return responses.respond(request, template, context=context)
+
return view_wrapper
--- a/app/soc/views/helper/responses.py Thu Jun 04 22:26:24 2009 +0200
+++ b/app/soc/views/helper/responses.py Thu Jun 04 23:21:33 2009 +0200
@@ -31,6 +31,7 @@
from soc.logic import accounts
from soc.logic import system
+from soc.logic.helper import timeline
from soc.logic.models import site
from soc.logic.models.user import logic as user_logic
from soc.modules import callback
@@ -137,6 +138,7 @@
context['site_name'] = settings.site_name
context['site_notice'] = settings.site_notice
context['tos_link'] = redirects.getToSRedirect(settings)
+ context['in_maintenance'] = timeline.isActivePeriod(site, 'maintenance')
return context