Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
django-rest-framework
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
django-rest-framework
Commits
10da18b2
Commit
10da18b2
authored
Sep 03, 2015
by
Tom Christie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Access settings lazily, not at module import
parent
39ec564a
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
13 additions
and
4 deletions
+13
-4
rest_framework/fields.py
+0
-0
rest_framework/serializers.py
+4
-1
rest_framework/settings.py
+9
-3
No files found.
rest_framework/fields.py
View file @
10da18b2
This diff is collapsed.
Click to expand it.
rest_framework/serializers.py
View file @
10da18b2
...
...
@@ -786,7 +786,7 @@ class ModelSerializer(Serializer):
# you'll also need to ensure you update the `create` method on any generic
# views, to correctly handle the 'Location' response header for
# "HTTP 201 Created" responses.
url_field_name
=
api_settings
.
URL_FIELD_NAME
url_field_name
=
None
# Default `create` and `update` behavior...
def
create
(
self
,
validated_data
):
...
...
@@ -869,6 +869,9 @@ class ModelSerializer(Serializer):
Return the dict of field names -> field instances that should be
used for `self.fields` when instantiating the serializer.
"""
if
self
.
url_field_name
is
None
:
self
.
url_field_name
=
api_settings
.
URL_FIELD_NAME
assert
hasattr
(
self
,
'Meta'
),
(
'Class {serializer_class} missing "Meta" attribute'
.
format
(
serializer_class
=
self
.
__class__
.
__name__
...
...
rest_framework/settings.py
View file @
10da18b2
...
...
@@ -26,7 +26,6 @@ from django.utils import six
from
rest_framework
import
ISO_8601
from
rest_framework.compat
import
importlib
USER_SETTINGS
=
getattr
(
settings
,
'REST_FRAMEWORK'
,
None
)
DEFAULTS
=
{
# Base API policies
...
...
@@ -188,10 +187,17 @@ class APISettings(object):
and return the class, rather than the string literal.
"""
def
__init__
(
self
,
user_settings
=
None
,
defaults
=
None
,
import_strings
=
None
):
self
.
user_settings
=
user_settings
or
{}
if
user_settings
:
self
.
_user_settings
=
user_settings
self
.
defaults
=
defaults
or
DEFAULTS
self
.
import_strings
=
import_strings
or
IMPORT_STRINGS
@property
def
user_settings
(
self
):
if
not
hasattr
(
self
,
'_user_settings'
):
self
.
_user_settings
=
getattr
(
settings
,
'REST_FRAMEWORK'
,
{})
return
self
.
_user_settings
def
__getattr__
(
self
,
attr
):
if
attr
not
in
self
.
defaults
.
keys
():
raise
AttributeError
(
"Invalid API setting: '
%
s'"
%
attr
)
...
...
@@ -212,7 +218,7 @@ class APISettings(object):
return
val
api_settings
=
APISettings
(
USER_SETTINGS
,
DEFAULTS
,
IMPORT_STRINGS
)
api_settings
=
APISettings
(
None
,
DEFAULTS
,
IMPORT_STRINGS
)
def
reload_api_settings
(
*
args
,
**
kwargs
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment