Enable the new middleware and empty the view decorator
authorSverre Rabbelier <srabbelier@gmail.com>
Sat, 12 Sep 2009 01:20:12 +0200
changeset 2904 395cff83dc83
parent 2903 bf17c6a843dd
child 2905 378833eb5a95
Enable the new middleware and empty the view decorator The view decorator should be removed entirely in a later commit.
app/settings.py
app/soc/views/helper/decorators.py
--- a/app/settings.py	Sat Sep 12 01:19:23 2009 +0200
+++ b/app/settings.py	Sat Sep 12 01:20:12 2009 +0200
@@ -85,8 +85,21 @@
 #     'django.template.loaders.eggs.load_template_source',
 )
 
+# The order of the middleware is as follows because:
+# - The ValueStore middleware should be before any other middleware
+#   so that the value store is available to it.
+# - The ExceptionHandler should be the outermost handler (after the
+#   ValueStore) so as to catch as many errors as possible.
+# - The Profile middleware should be as outmost as possible, so that
+#   as many function calls as possible, but it cannot be before the
+#   ExceptionHandler (so as to catch exceptions thrown by it).
+# - The MaintenanceMiddleware should be after the Profiler, since we
+#   do want it's actions profiled.
 MIDDLEWARE_CLASSES = (
+    'soc.middleware.value_store.ValueStoreMiddleware',
+    'soc.middleware.exception_handler.ExceptionHandlerMiddleware',
     'app_profiler.app_profiler.ProfileMiddleware',    
+    'soc.middleware.maintenance.MaintenanceMiddleware',
 #    'django.middleware.common.CommonMiddleware',
 #    'django.contrib.sessions.middleware.SessionMiddleware',
 #    'django.contrib.auth.middleware.AuthenticationMiddleware',
--- a/app/soc/views/helper/decorators.py	Sat Sep 12 01:19:23 2009 +0200
+++ b/app/soc/views/helper/decorators.py	Sat Sep 12 01:20:12 2009 +0200
@@ -27,23 +27,13 @@
 
 from functools import wraps
 
-from google.appengine.runtime import DeadlineExceededError
-from google.appengine.runtime.apiproxy_errors import CapabilityDisabledError
-
 from django import http
 from django.utils.translation import ugettext
 
 from soc.logic import dicts
-from soc.modules import callback
 from soc.views.helper import responses
 
 
-DEF_DOWN_FOR_MAINTENANCE_MSG = ugettext("Down for maintenance")
-DEF_IN_UNEXPECTED_MAINTENANCE_MSG = ugettext(
-      "Down for unexpected maintenance.")
-
-
-
 class Error(Exception):
   """Base class for all exceptions raised by this module.
   """
@@ -51,75 +41,16 @@
   pass
 
 
-def maintenance(request):
-  """Returns a 'down for maintenance' view.
-  """
-
-  context = responses.getUniversalContext(request)
-  context['page_name'] = ugettext('Maintenance')
-
-  notice = context.pop('site_notice')
-
-  if not notice:
-    context['body_content'] = DEF_IN_UNEXPECTED_MAINTENANCE_MSG
-  else:
-    context['body_content'] = notice
-
-  context['header_title'] = DEF_DOWN_FOR_MAINTENANCE_MSG
-  context['sidebar_menu_items'] = [
-      {'heading': DEF_DOWN_FOR_MAINTENANCE_MSG,
-       'group': ''},
-      ]
-
-  template = 'soc/base.html'
-
-  return responses.respond(request, template, context=context)
-
-
 def view(func):
   """Decorator that insists that exceptions are handled by view.
   """
 
-  from soc.views import out_of_band
-
   @wraps(func)
   def view_wrapper(request, *args, **kwds):
     """View decorator wrapper method.
     """
 
-    core = callback.getCore()
-    core.startNewRequest(request)
-
-    def view_wrapper_helper():
-      """View wrapper helper that does all the work.
-      """
-
-      context = responses.getUniversalContext(request)
-
-      try:
-        if not context['is_admin'] and context['in_maintenance']:
-          return maintenance(request)
-
-        return func(request, *args, **kwds)
-      except CapabilityDisabledError, exception:
-        logging.exception(exception)
-        # assume the site is in maintenance if we get CDE
-        return maintenance(request)
-      except DeadlineExceededError, exception:
-        template = 'soc/deadline_exceeded.html'
-      except MemoryError, exception:
-        template = 'soc/memory_error.html'
-      except AssertionError, exception:
-        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)
-
-    result = view_wrapper_helper()
-    core.endRequest(request)
-    return result
+    return func(request, *args, **kwds)
 
   return view_wrapper