Beispiel #1
0
 def dispatch(self, request, *args, **kwargs):
     """ Return the view with a 503 status code """
     if not get_current_site_messages(request).count():
         # Status code 200: OK
         return HttpResponse("OK")
     else:
         # Status code 503: Service Unavailable
         return HttpResponse("Service Unavailable", status=503)
Beispiel #2
0
    def process_request(self, request):
        if request.META.get('REMOTE_ADDR') in settings.INTERNAL_IPS:
            # Allow access if remote ip is in INTERNAL_IPS
            return None
        elif is_privileged_request(request):
            # Allow privileged users (superusers and possibly staff) through
            return None
        else:
            try:
                view, args, kwargs = urlresolvers.resolve(request.path)
            except:
                return None
            if 'django.contrib.admin' in view.__module__ or  'django.views.static' in view.__module__ or 'maintenance.heartbeat' in view.__module__:
                return None

        messages = get_current_site_messages(request)
        if messages.count() > 0:
            return TemplateResponse(request, '503.html', context={'maintenance_messages': messages}, status=503)
        else:
           return None