Thursday, March 18, 2010

Re: Multiple host-based settings file

Hi,
Thanks for your replies.
What I finally decided on was:

Step 1: Create a middleware to make the current request accessible
everywhere-

from threading import local
CURRENT_REQUEST=local()
class CurrentRequestMiddleware(object):
"""
"CurrentRequestMiddleware" :
"""
def process_request(self, request):
CURRENT_REQUEST.request=request

Step 2: Add a __getattr__ method to django.conf.LazySettings file to
return host specific setting if avaiable

from django.middleware.CurrentRequestMiddleware import CURRENT_REQUEST

def __getattr__(self, name):
try:

specific_setting=get_host_specific_setting(CURRENT_REQUEST.request.getHostname())
if specific_setting:
return specific_setting
except:
pass
return super(LazySettings,self).__getattr__(name)

Step 3:
Create a normal django appto store custom settings in the
database and implement the get_host_specific_setting used above

So far it is running well enough on dev. Any problems which i cannot
foresse?

Thanks,
Shitiz

--
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 django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment