1 from django.conf import settings
2 from django.core import urlresolvers
4 # This is django-maintancemode v. 0.9.2
6 from django.conf.urls import defaults
7 defaults.handler503 = 'maintenancemode.views.defaults.temporary_unavailable'
8 defaults.__all__.append('handler503')
10 from maintenancemode.conf.settings import MAINTENANCE_MODE
13 class MaintenanceModeMiddleware(object):
14 def process_request(self, request):
15 # Allow access if middleware is not activated
16 if not MAINTENANCE_MODE:
19 # Allow access if remote ip is in INTERNAL_IPS
20 if request.META.get('REMOTE_ADDR') in settings.INTERNAL_IPS:
23 # Allow acess if the user doing the request is logged in and a
25 if hasattr(request, 'user') and request.user.is_staff:
28 # Otherwise show the user the 503 page
29 resolver = urlresolvers.get_resolver(None)
31 callback, param_dict = resolver._resolve_special('503')
32 return callback(request, **param_dict)
34 def process_exception(self, request, exception):
35 tb_text = traceback.format_exc()
36 url = request.build_absolute_uri()
37 request.META['wsgi.errors'].write(url + '\n' + str(tb_text) + '\n')