I am using Django 1.3 with mod_wsgi
In my settings.py
DISABLE_SYSTEM = False
DISABLE_USER_INTERFACE = False
MIDDLEWARE_CLASSES = [
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
]
if DISABLE_SYSTEM:
MIDDLEWARE_CLASSES.insert(0, 'SomeMiddleware')
if DISABLE_USER_INTERFACE:
MIDDLEWARE_CLASSES.append('SomeOtherMiddleware')
When i set DISABLE_SYSTEM to True, SomeMiddleware's process_request function returns a warning message with HttpResponse and following Middewares do not run at all. That gives me a kind of System shutdown for maintenance
DISABLE_USER_INTERFACE filters request and any view function called by a user is blocked, while admin urls and management functions runs normally.
Up to now, i used this for maintenance of different kinds, and i simply change it from the file and touch wsgi to re-reload python modules. But now, i need to use a kind of scheduled routine to stop user based requests and do some maintanance on the background and some from admin.
At this point, i system (but not user) needs to set DISABLE_USER_INTERFACE to True from settings.py and start maintenance. But i could not find porper way to do it or a better way to handle this not from settings.py but somewhere else.
Lines in settings py than changes DISABLE_USER_INTERFACE is because i need to use this function once per day and using these two middleware for each request do not seem logical to me. So in my current model, they run only when they are needed to be run
Any suggestions will be appreciated.
UPDATE: What i want to do is disabling user interface during 19:00 - 19:30 everyday. I am not sure about making a middleware level check like:
if 19:00<now()<19:30:
stop system
for every request. I need something more efficient that avoids unnecessary process. Or is middleware the right choice for that kind of works?