Ticket #904: django-env_w_sympathy4win.diff

File django-env_w_sympathy4win.diff, 2.5 KB (added by deric <deric@…>, 19 years ago)
  • utils/translation.py

     
    117117
    118118    globalpath = os.path.join(os.path.dirname(settings.__file__), 'locale')
    119119
    120     parts = os.environ['DJANGO_SETTINGS_MODULE'].split('.')
     120    parts = settings.ROOT_URLCONF.split('.')
    121121    project = __import__(parts[0], {}, {}, [])
    122122    projectpath = os.path.join(os.path.dirname(project.__file__), 'locale')
    123123
  • conf/settings.py

     
    88
    99import os
    1010import sys
     11import os.path
     12import imp
    1113from django.conf import global_settings
    1214
    1315ENVIRONMENT_VARIABLE = "DJANGO_SETTINGS_MODULE"
     16SETTINGS_FILE = "settings.py"
    1417
    1518# get a reference to this module (why isn't there a __module__ magic var?)
    1619me = sys.modules[__name__]
     
    2023    if setting == setting.upper():
    2124        setattr(me, setting, getattr(global_settings, setting))
    2225
    23 # try to load DJANGO_SETTINGS_MODULE
     26# try to load DJANGO_SETTINGS_MODULE if not found walk the filesystem upwards
     27# to find SETTINGS_FILE. If file is not found either raise EnvironmentError.
    2428try:
    2529    me.SETTINGS_MODULE = os.environ[ENVIRONMENT_VARIABLE]
    2630    if not me.SETTINGS_MODULE: # If it's set but is an empty string.
    2731        raise KeyError
    2832except KeyError:
    29     raise EnvironmentError, "Environment variable %s is undefined." % ENVIRONMENT_VARIABLE
     33    cwd = os.getcwdu()
     34   
     35    while (cwd != '/' and cwd != 'C:\\'):
     36        if os.path.exists(cwd + os.path.sep + SETTINGS_FILE):
     37            mod = imp.load_source('settings', cwd + os.path.sep + SETTINGS_FILE)
     38            break
     39        else:
     40            cwd = os.path.split(cwd)[0]
     41    else:
     42        raise EnvironmentError, "Environment variable %s is undefined." % \
     43            ENVIRONMENT_VARIABLE
     44else:
     45    try:
     46        mod = __import__(me.SETTINGS_MODULE, '', '', [''])
     47    except ImportError, e:
     48        raise EnvironmentError, "Could not import %s '%s' (is it on sys.path?): %s" % \
     49            (ENVIRONMENT_VARIABLE, me.SETTINGS_MODULE, e)
    3050
    31 try:
    32     mod = __import__(me.SETTINGS_MODULE, '', '', [''])
    33 except ImportError, e:
    34     raise EnvironmentError, "Could not import %s '%s' (is it on sys.path?): %s" % (ENVIRONMENT_VARIABLE, me.SETTINGS_MODULE, e)
    35 
    3651# Settings that should be converted into tuples if they're mistakenly entered
    3752# as strings.
    3853tuple_settings = ("INSTALLED_APPS", "TEMPLATE_DIRS")
Back to Top