aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTom Christie2012-09-06 15:57:16 +0100
committerTom Christie2012-09-06 15:57:16 +0100
commitc707034649fa9e24f0c6c3c0580dc06f90eac373 (patch)
tree90bdb2411f1dbaccbf95ba440dba1029cc019526
parent74c50b953557ea283a6cd601ad3656379369eb47 (diff)
downloaddjango-rest-framework-c707034649fa9e24f0c6c3c0580dc06f90eac373.tar.bz2
Add more settings to settings.py
-rw-r--r--djangorestframework/settings.py40
-rw-r--r--docs/api-guide/settings.md8
2 files changed, 26 insertions, 22 deletions
diff --git a/djangorestframework/settings.py b/djangorestframework/settings.py
index f25133d5..dc0cc51b 100644
--- a/djangorestframework/settings.py
+++ b/djangorestframework/settings.py
@@ -29,6 +29,12 @@ DEFAULTS = {
'djangorestframework.parsers.JSONParser',
'djangorestframework.parsers.FormParser'
),
+ 'DEFAULT_AUTHENTICATION': (
+ 'djangorestframework.authentication.SessionAuthentication',
+ 'djangorestframework.authentication.UserBasicAuthentication'
+ ),
+ 'DEFAULT_PERMISSIONS': (),
+ 'DEFAULT_THROTTLES': (),
'UNAUTHENTICATED_USER': 'django.contrib.auth.models.AnonymousUser',
'UNAUTHENTICATED_TOKEN': None
}
@@ -40,6 +46,10 @@ if yaml:
# List of settings that may be in string import notation.
IMPORT_STRINGS = (
'DEFAULT_RENDERERS',
+ 'DEFAULT_PARSERS',
+ 'DEFAULT_AUTHENTICATION',
+ 'DEFAULT_PERMISSIONS',
+ 'DEFAULT_THROTTLES',
'UNAUTHENTICATED_USER',
'UNAUTHENTICATED_TOKEN'
)
@@ -53,26 +63,26 @@ def perform_import(val, setting):
if val is None or setting not in IMPORT_STRINGS:
return val
- try:
- if isinstance(val, basestring):
- return import_from_string(val)
- elif isinstance(val, (list, tuple)):
- return [import_from_string(item) for item in val]
- return val
- except:
- msg = "Could not import '%s' for API setting '%s'" % (val, setting)
- raise ImportError(msg)
+ if isinstance(val, basestring):
+ return import_from_string(val, setting)
+ elif isinstance(val, (list, tuple)):
+ return [import_from_string(item, setting) for item in val]
+ return val
-def import_from_string(val):
+def import_from_string(val, setting):
"""
Attempt to import a class from a string representation.
"""
- # Nod to tastypie's use of importlib.
- parts = val.split('.')
- module_path, class_name = '.'.join(parts[:-1]), parts[-1]
- module = importlib.import_module(module_path)
- return getattr(module, class_name)
+ try:
+ # Nod to tastypie's use of importlib.
+ parts = val.split('.')
+ module_path, class_name = '.'.join(parts[:-1]), parts[-1]
+ module = importlib.import_module(module_path)
+ return getattr(module, class_name)
+ except:
+ msg = "Could not import '%s' for API setting '%s'" % (val, setting)
+ raise ImportError(msg)
class APISettings(object):
diff --git a/docs/api-guide/settings.md b/docs/api-guide/settings.md
index fd35fbc6..882571e1 100644
--- a/docs/api-guide/settings.md
+++ b/docs/api-guide/settings.md
@@ -40,19 +40,13 @@ Default:
A list or tuple of authentication classes, that determines the default set of authenticators used when accessing the `request.user` or `request.auth` properties.
-Default if `DEBUG` is `True`:
+Default:
(
'djangorestframework.authentication.SessionAuthentication',
'djangorestframework.authentication.UserBasicAuthentication'
)
-Default if `DEBUG` is `False`:
-
- (
- 'djangorestframework.authentication.SessionAuthentication',
- )
-
## DEFAULT_PERMISSIONS
A list or tuple of permission classes, that determines the default set of permissions checked at the start of a view.