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
12 class MaintenanceModeMiddleware(object):
13 def process_request(self, request):
14 # Allow access if middleware is not activated
15 if not MAINTENANCE_MODE:
18 # Allow access if remote ip is in INTERNAL_IPS
19 if request.META.get('REMOTE_ADDR') in settings.INTERNAL_IPS:
22 # Allow acess if the user doing the request is logged in and a
24 if hasattr(request, 'user') and request.user.is_staff:
27 # Otherwise show the user the 503 page
28 resolver = urlresolvers.get_resolver(None)
30 callback, param_dict = resolver._resolve_special('503')
31 return callback(request, **param_dict)