app/soc/views/helper/decorators.py
changeset 1585 06fb5950cb03
parent 1582 f2f352ad193f
child 1592 4465cda55182
--- a/app/soc/views/helper/decorators.py	Sun Mar 01 20:20:47 2009 +0000
+++ b/app/soc/views/helper/decorators.py	Sun Mar 01 20:39:21 2009 +0000
@@ -27,7 +27,10 @@
 
 from functools import wraps
 
+from google.appengine.api import users
 from google.appengine.runtime import DeadlineExceededError
+from google.appengine.runtime.apiproxy_errors import CapabilityDisabledError
+
 
 from django import http
 
@@ -41,13 +44,29 @@
 def view(func):
   """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
+
   @wraps(func)
-  def view_wrapper(*args, **kwds):
+  def view_wrapper(request, *args, **kwds):
+    site = site_logic.getSingleton()
+
+    # don't redirect admins, or if we're at /maintenance already
+    no_redirect = users.is_current_user_admin() or request.path == '/maintenance'
+
+    if (not no_redirect) and timeline.isAfterEvent(site, 'maintenance_start'):
+      return http.HttpResponseRedirect('/maintenance')
+
     try:
-      return func(*args, **kwds)
+      return func(request, *args, **kwds)
     except DeadlineExceededError, e:
       logging.exception(e)
       return http.HttpResponseRedirect('/soc/content/deadline_exceeded.html')
+    except CapabilityDisabledError, e:
+      logging.exception(e)
+      # assume the site is in maintenance if we get CDE
+      return http.HttpResponseRedirect('/maintenance')
     except MemoryError, e:
       logging.exception(e)
       return http.HttpResponseRedirect('/soc/content/memory_error.html')