Ticket #13053: a_s-draft.diff

File a_s-draft.diff, 1.7 KB (added by Mathias Nielsen, 14 years ago)

Initial draft of the idea. Most likely not commit-ready.

  • django/conf/__init__.py

     
    149149    # For Python < 2.6:
    150150    __members__ = property(lambda self: self.__dir__())
    151151
    152 settings = LazySettings()
     152# Must be set here to be used within ActiveSettings
     153LAZY_SETTINGS = LazySettings()
    153154
     155class ActiveSettings(object):
     156    """
     157    Serves ActiveSettings. Falls back to LazySettings() for everything else.
     158    """
     159    def __init__(self):
     160        self.lazy_settings = LAZY_SETTINGS
     161    def __getattr__(self, name):
     162        active_settings = getattr(self.lazy_settings, 'ACTIVE_SETTINGS')
     163        if name in active_settings:
     164            return importlib.import_module(active_settings[name])
     165        else:
     166            return getattr(self.lazy_settings, name)
     167    def __dir__(self):
     168        return self.__dict__.keys() + dir(self.lazy_settings)
     169
     170    # For Python < 2.6:
     171    __members__ = property(lambda self: self.__dir__())         
     172
     173# Just to make sure that the overhead of ActiveSettings is only introduced if it is configured.
     174if LAZY_SETTINGS.ACTIVE_SETTINGS:
     175    settings = ActiveSettings()
     176else:
     177    settings = LAZY_SETTINGS
     178
  • django/conf/global_settings.py

     
    386386DEFAULT_TABLESPACE = ''
    387387DEFAULT_INDEX_TABLESPACE = ''
    388388
     389# Dictionary of settings that will be made active. Example below
     390# ACTIVE_SETTINGS = {'EMAIL_HOST': 'myproject.myapp.myfile.mycallable'}
     391ACTIVE_SETTINGS = {}
     392
    389393##############
    390394# MIDDLEWARE #
    391395##############
Back to Top