Make the maintenance page a hardcoded response
Show the maintenance message on the requested page, instead of
redirecting to a specific url which then displays a page with the
maintenance notice.
--- a/app/soc/views/helper/decorators.py Thu Jun 04 22:08:11 2009 +0200
+++ b/app/soc/views/helper/decorators.py Thu Jun 04 22:26:24 2009 +0200
@@ -30,10 +30,17 @@
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.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):
@@ -43,6 +50,31 @@
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.
"""
@@ -61,11 +93,11 @@
try:
site = site_logic.getSingleton()
- # don't redirect admins, or if we're at /maintenance already
- no_redirect = user_logic.isDeveloper() or request.path == '/maintenance'
+ # don't redirect admins
+ redirect = not user_logic.isDeveloper()
- if (not no_redirect) and timeline.isActivePeriod(site, 'maintenance'):
- return http.HttpResponseRedirect('/maintenance')
+ if redirect and timeline.isActivePeriod(site, 'maintenance'):
+ return maintenance(request)
return func(request, *args, **kwds)
except DeadlineExceededError, exception:
--- a/app/soc/views/models/site.py Thu Jun 04 22:08:11 2009 +0200
+++ b/app/soc/views/models/site.py Thu Jun 04 22:26:24 2009 +0200
@@ -46,10 +46,6 @@
"""View methods for the Document model.
"""
- DEF_DOWN_FOR_MAINTENANCE_MSG = ugettext("Down for maintenance")
- DEF_NOT_IN_MAINTENANCE_MSG = ugettext(
- "The site is currently not in maintenance mode.")
-
def __init__(self, params=None):
"""Defines the fields and methods required for the base View class
to provide the user with list, public, create, edit and delete views.
@@ -102,10 +98,6 @@
patterns += [(r'^$', 'soc.views.models.%(module_name)s.main_public',
page_name)]
- page_name = "Maintenance"
- patterns += [(r'^maintenance$',
- 'soc.views.models.%(module_name)s.maintenance', page_name)]
-
page_name = "Edit Site"
patterns += [(r'^%(url_name)s/(?P<access_type>edit)$',
'soc.views.models.%(module_name)s.main_edit',
@@ -159,29 +151,6 @@
params = dicts.merge(params, new_params)
return super(View, self).getSidebarMenus(id, user, params=params)
- def maintenance(self, request, page_name):
- """Returns a 'down for maintenance' view.
- """
-
- context = responses.getUniversalContext(request)
- context['page_name'] = page_name
-
- notice = context.pop('site_notice')
-
- if not notice:
- context['body_content'] = self.DEF_NOT_IN_MAINTENANCE_MSG
- else:
- context['body_content'] = notice
- context['header_title'] = self.DEF_DOWN_FOR_MAINTENANCE_MSG
- context['sidebar_menu_items'] = [
- {'heading': self.DEF_DOWN_FOR_MAINTENANCE_MSG,
- 'group': ''},
- ]
-
- template = 'soc/base.html'
-
- return responses.respond(request, template, context=context)
-
def mainPublic(self, request, page_name=None, **kwargs):
"""Displays the main site settings page.
@@ -230,5 +199,4 @@
export = decorators.view(view.export)
main_public = decorators.view(view.mainPublic)
main_edit = decorators.view(view.mainEdit)
-maintenance = decorators.view(view.maintenance)
home = decorators.view(view.home)