> Hi there!
> 
> How would one handle the following tasks in a middleware?
> 
> If a settings called "MAINTENANCE" is true, check if the user is logged in. 
> If 
> he is, let him view the requested page normally. If not, redirect to 
> maintenance page.
> 
> If setting is false, show page normally despite user logged in or not.
> 
> It's a way to show unauthorised users an "under construction" page while the 
> maintenance settings is set to true.
> 
> Can anyone give me some advice, or perhaps point me to someone who already 
> solved this task?
> 
Something like this (i didn't check if this code works):

from django.conf import settings
from django.http import HttpResponseRedirect

class MaintenanceMiddleware(object):
     def process_request(self, request):
         if settings.MAINTENANCE:
             if not request.user.is_authenticated():
                 return HttpResponseRedirect('/maintenance/')
     return None

Put this middleware after AuthenticationMiddleware in the settings.py

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to