# HG changeset patch # User Sverre Rabbelier # Date 1235939961 0 # Node ID 06fb5950cb03024c6bcb63abe38f8f1563558423 # Parent d8ba8c917f3782eefe36cff8eaa08ed34a70cf47 Make it possible to put the site in maintenance mode By specifying the UTC date from which the maintenance shoulds start, developers can put the site in 'maintenance' mode. Also redirect to /maintenance if we get a CapabilityDisabledError. Patch by: Sverre Rabbelier diff -r d8ba8c917f37 -r 06fb5950cb03 app/soc/models/site.py --- a/app/soc/models/site.py Sun Mar 01 20:20:47 2009 +0000 +++ b/app/soc/models/site.py Sun Mar 01 20:39:21 2009 +0000 @@ -46,6 +46,9 @@ site_notice = db.StringProperty(verbose_name=ugettext('Site Notice')) site_notice.help_text = ugettext('A notice that will be displayed site-wide') + maintenance_start = db.DateTimeProperty( + verbose_name=ugettext('Maintenance start date')) + #: Valid Google Analytics tracking number, if entered every page #: is going to have Google Analytics JS initialization code in #: the footer with the given tracking number. diff -r d8ba8c917f37 -r 06fb5950cb03 app/soc/views/helper/decorators.py --- 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') diff -r d8ba8c917f37 -r 06fb5950cb03 app/soc/views/helper/responses.py --- a/app/soc/views/helper/responses.py Sun Mar 01 20:20:47 2009 +0000 +++ b/app/soc/views/helper/responses.py Sun Mar 01 20:39:21 2009 +0000 @@ -20,6 +20,7 @@ __authors__ = [ '"Todd Larsen" ', '"Pawel Solyga" ', + '"Sverre Rabbelier" ', ]