2005-07-13 09:25:57 +08:00
|
|
|
"""
|
|
|
|
Settings and configuration for Django.
|
|
|
|
|
|
|
|
Values will be read from the module specified by the DJANGO_SETTINGS_MODULE environment
|
2005-07-19 22:44:27 +08:00
|
|
|
variable, and then from django.conf.global_settings; see the global settings file for
|
2005-07-13 09:25:57 +08:00
|
|
|
a list of all possible variables.
|
|
|
|
"""
|
|
|
|
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
from django.conf import global_settings
|
|
|
|
|
2005-07-19 22:44:27 +08:00
|
|
|
# get a reference to this module (why isn't there a __module__ magic var?)
|
2005-07-13 09:25:57 +08:00
|
|
|
me = sys.modules[__name__]
|
|
|
|
|
|
|
|
# update this dict from global settings (but only for ALL_CAPS settings)
|
|
|
|
for setting in dir(global_settings):
|
|
|
|
if setting == setting.upper():
|
|
|
|
setattr(me, setting, getattr(global_settings, setting))
|
|
|
|
|
2005-07-17 00:07:04 +08:00
|
|
|
# try to load DJANGO_SETTINGS_MODULE
|
2005-07-13 09:25:57 +08:00
|
|
|
try:
|
2005-07-17 00:07:04 +08:00
|
|
|
me.SETTINGS_MODULE = os.environ["DJANGO_SETTINGS_MODULE"]
|
|
|
|
except KeyError:
|
2005-07-19 22:44:27 +08:00
|
|
|
raise EnvironmentError, "Environment variable DJANGO_SETTINGS_MODULE is undefined."
|
2005-07-17 00:07:04 +08:00
|
|
|
|
|
|
|
try:
|
|
|
|
mod = __import__(me.SETTINGS_MODULE, '', '', [''])
|
|
|
|
except ImportError, e:
|
2005-07-17 00:10:04 +08:00
|
|
|
raise EnvironmentError, "Could not import DJANGO_SETTINGS_MODULE '%s' (is it on sys.path?): %s" % (me.SETTINGS_MODULE, e)
|
2005-07-17 00:07:04 +08:00
|
|
|
|
2005-07-20 01:58:01 +08:00
|
|
|
# Settings that should be converted into tuples if they're mistakenly entered
|
|
|
|
# as strings.
|
|
|
|
tuple_settings = ("INSTALLED_APPS", "TEMPLATE_DIRS")
|
|
|
|
|
2005-07-17 00:07:04 +08:00
|
|
|
for setting in dir(mod):
|
|
|
|
if setting == setting.upper():
|
2005-07-20 01:58:01 +08:00
|
|
|
setting_value = getattr(mod, setting)
|
|
|
|
if setting in tuple_settings and type(setting_value) == str:
|
|
|
|
setting_value = (setting_value,) # In case the user forgot the comma.
|
|
|
|
setattr(me, setting, setting_value)
|
2005-07-13 09:25:57 +08:00
|
|
|
|
|
|
|
# save DJANGO_SETTINGS_MODULE in case anyone in the future cares
|
|
|
|
me.SETTINGS_MODULE = os.environ.get('DJANGO_SETTINGS_MODULE', '')
|
2005-07-19 22:44:27 +08:00
|
|
|
|
2005-07-13 09:25:57 +08:00
|
|
|
# move the time zone info into os.environ
|
|
|
|
os.environ['TZ'] = me.TIME_ZONE
|
|
|
|
|
|
|
|
# finally, clean up my namespace
|
|
|
|
for k in dir(me):
|
|
|
|
if not k.startswith('_') and k != 'me' and k != k.upper():
|
|
|
|
delattr(me, k)
|
|
|
|
del me, k
|
|
|
|
|