Ticket #16628: application-settings-holder.diff

File application-settings-holder.diff, 1.1 KB (added by Matt Magin, 13 years ago)

Replacement patch that is properly formatted.

  • django/conf/__init__.py

     
    169169    # For Python < 2.6:
    170170    __members__ = property(lambda self: self.__dir__())
    171171
     172
     173class ApplicationSettingsHolder(BaseSettings):
     174    """
     175    Holder for application-specific settings.
     176    """
     177    def __init__(self, application_settings):
     178        """
     179        Requests for configuration variables first check the project_settings module
     180        and falls back to application_settings if not found.
     181        """
     182        try:
     183            mod = importlib.import_module(application_settings)
     184        except ImportError, e:
     185            raise ImportError("Could not import application settings '%s': %s" % (application_settings, e))
     186        for setting in dir(mod):
     187            if setting == setting.upper() and not hasattr(settings, setting.upper()):
     188                setattr(self, setting, getattr(mod, setting))
     189
     190    def __getattr__(self, name):
     191        return getattr(settings, name)
     192
     193
    172194settings = LazySettings()
    173195
    174196
Back to Top