Zmiana typu błędnie oznaczonego szablonu z text/javascript na text/html.
[redakcja.git] / apps / maintenancemode / middleware.py
1 from django.conf import settings
2 from django.core import urlresolvers
3
4 # This is django-maintancemode v. 0.9.2
5
6 from django.conf.urls import defaults
7 defaults.handler503 = 'maintenancemode.views.defaults.temporary_unavailable'
8 defaults.__all__.append('handler503')
9
10 from maintenancemode.conf.settings import MAINTENANCE_MODE
11
12 class MaintenanceModeMiddleware(object):
13     def process_request(self, request):
14         # Allow access if middleware is not activated
15         if not MAINTENANCE_MODE:
16             return None
17
18         # Allow access if remote ip is in INTERNAL_IPS
19         if request.META.get('REMOTE_ADDR') in settings.INTERNAL_IPS:
20             return None
21         
22         # Allow acess if the user doing the request is logged in and a
23         # staff member.
24         if hasattr(request, 'user') and request.user.is_staff:
25             return None
26         
27         # Otherwise show the user the 503 page
28         resolver = urlresolvers.get_resolver(None)
29         
30         callback, param_dict = resolver._resolve_special('503')
31         return callback(request, **param_dict)