Permalink
Browse files

multi-auth: Merged to [2964]

git-svn-id: http://code.djangoproject.com/svn/django/branches/multi-auth@2965 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
1 parent d659956 commit 681763a29c9d82858a214a6898e807be0c835c47 @jkocherhans jkocherhans committed May 22, 2006
Showing with 2,660 additions and 1,723 deletions.
  1. +80 −13 django/conf/__init__.py
  2. BIN django/conf/locale/he/LC_MESSAGES/django.mo
  3. +66 −190 django/conf/locale/he/LC_MESSAGES/django.po
  4. BIN django/conf/locale/ja/LC_MESSAGES/django.mo
  5. +1,154 −1,154 django/conf/locale/ja/LC_MESSAGES/django.po
  6. BIN django/conf/locale/zh_CN/LC_MESSAGES/django.mo
  7. +158 −249 django/conf/locale/zh_CN/LC_MESSAGES/django.po
  8. +1 −0 django/contrib/admin/templates/admin_doc/model_detail.html
  9. +7 −4 django/contrib/admin/views/doc.py
  10. +2 −1 django/contrib/auth/decorators.py
  11. +26 −0 django/contrib/sites/managers.py
  12. +3 −0 django/core/management.py
  13. 0 django/db/backends/postgresql_psycopg2/__init__.py
  14. +123 −0 django/db/backends/postgresql_psycopg2/base.py
  15. +1 −0 django/db/backends/postgresql_psycopg2/client.py
  16. +1 −0 django/db/backends/postgresql_psycopg2/creation.py
  17. +85 −0 django/db/backends/postgresql_psycopg2/introspection.py
  18. +3 −3 django/db/models/base.py
  19. +7 −3 django/template/defaultfilters.py
  20. +7 −4 django/utils/translation.py
  21. +1 −1 django/views/generic/create_update.py
  22. +35 −10 docs/add_ons.txt
  23. +54 −0 docs/authentication.txt
  24. +1 −1 docs/db-api.txt
  25. +49 −0 docs/django-admin.txt
  26. +53 −44 docs/generic_views.txt
  27. +11 −0 docs/i18n.txt
  28. +11 −3 docs/install.txt
  29. +6 −2 docs/middleware.txt
  30. +94 −12 docs/model-api.txt
  31. +78 −0 docs/settings.txt
  32. +311 −0 docs/sites.txt
  33. +196 −0 docs/templates_python.txt
  34. +16 −16 docs/tutorial01.txt
  35. +1 −0 tests/othertests/templates.py
  36. +19 −13 tests/runtests.py
View
@@ -12,10 +12,63 @@
ENVIRONMENT_VARIABLE = "DJANGO_SETTINGS_MODULE"
-class Settings:
+class LazySettings:
+ """
+ A lazy proxy for either global Django settings or a custom settings object.
+ The user can manually configure settings prior to using them. Otherwise,
+ Django uses the settings module pointed to by DJANGO_SETTINGS_MODULE.
+ """
+ def __init__(self):
+ # _target must be either None or something that supports attribute
+ # access (getattr, hasattr, etc).
+ self._target = None
+
+ def __getattr__(self, name):
+ if self._target is None:
+ self._import_settings()
+ if name == '__members__':
+ # Used to implement dir(obj), for example.
+ return self._target.get_all_members()
+ return getattr(self._target, name)
+
+ def __setattr__(self, name, value):
+ if name == '_target':
+ # Assign directly to self.__dict__, because otherwise we'd call
+ # __setattr__(), which would be an infinite loop.
+ self.__dict__['_target'] = value
+ else:
+ setattr(self._target, name, value)
+
+ def _import_settings(self):
+ """
+ Load the settings module pointed to by the environment variable. This
+ is used the first time we need any settings at all, if the user has not
+ previously configured the settings manually.
+ """
+ try:
+ settings_module = os.environ[ENVIRONMENT_VARIABLE]
+ if not settings_module: # If it's set but is an empty string.
+ raise KeyError
+ except KeyError:
+ raise EnvironmentError, "Environment variable %s is undefined." % ENVIRONMENT_VARIABLE
+
+ self._target = Settings(settings_module)
+
+ def configure(self, default_settings=global_settings, **options):
+ """
+ Called to manually configure the settings. The 'default_settings'
+ parameter sets where to retrieve any unspecified values from (its
+ argument must support attribute access (__getattr__)).
+ """
+ if self._target != None:
+ raise EnvironmentError, 'Settings already configured.'
+ holder = UserSettingsHolder(default_settings)
+ for name, value in options.items():
+ setattr(holder, name, value)
+ self._target = holder
+class Settings:
def __init__(self, settings_module):
-
# update this dict from global settings (but only for ALL_CAPS settings)
for setting in dir(global_settings):
if setting == setting.upper():
@@ -27,7 +80,7 @@ def __init__(self, settings_module):
try:
mod = __import__(self.SETTINGS_MODULE, '', '', [''])
except ImportError, e:
- raise EnvironmentError, "Could not import settings '%s' (is it on sys.path?): %s" % (self.SETTINGS_MODULE, e)
+ raise EnvironmentError, "Could not import settings '%s' (Is it on sys.path? Does it have syntax errors?): %s" % (self.SETTINGS_MODULE, e)
# Settings that should be converted into tuples if they're mistakenly entered
# as strings.
@@ -56,18 +109,32 @@ def __init__(self, settings_module):
# move the time zone info into os.environ
os.environ['TZ'] = self.TIME_ZONE
-# try to load DJANGO_SETTINGS_MODULE
-try:
- settings_module = os.environ[ENVIRONMENT_VARIABLE]
- if not settings_module: # If it's set but is an empty string.
- raise KeyError
-except KeyError:
- raise EnvironmentError, "Environment variable %s is undefined." % ENVIRONMENT_VARIABLE
+ def get_all_members(self):
+ return dir(self)
+
+class UserSettingsHolder:
+ """
+ Holder for user configured settings.
+ """
+ # SETTINGS_MODULE does not really make sense in the manually configured
+ # (standalone) case.
+ SETTINGS_MODULE = None
-# instantiate the configuration object
-settings = Settings(settings_module)
+ def __init__(self, default_settings):
+ """
+ Requests for configuration variables not in this class are satisfied
+ from the module specified in default_settings (if possible).
+ """
+ self.default_settings = default_settings
+
+ def __getattr__(self, name):
+ return getattr(self.default_settings, name)
+
+ def get_all_members(self):
+ return dir(self) + dir(self.default_settings)
+
+settings = LazySettings()
# install the translation machinery so that it is available
from django.utils import translation
translation.install()
-
Binary file not shown.
Oops, something went wrong.

0 comments on commit 681763a

Please sign in to comment.