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
40e09472
Commit
40e09472
authored
Jun 06, 2013
by
Tom Christie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Never deepcopy validators. Closes #913
parent
181e4fdd
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
21 additions
and
29 deletions
+21
-29
docs/api-guide/generic-views.md
+1
-1
rest_framework/fields.py
+12
-27
rest_framework/views.py
+8
-1
No files found.
docs/api-guide/generic-views.md
View file @
40e09472
...
...
@@ -131,7 +131,7 @@ You may want to override this method to provide more complex behavior such as mo
For example
:
def get_paginate_by(self)
:
self.request.accepted_renderer.format == 'html'
:
if
self.request.accepted_renderer.format == 'html'
:
return 20
return 100
...
...
rest_framework/fields.py
View file @
40e09472
...
...
@@ -7,25 +7,24 @@ from __future__ import unicode_literals
import
copy
import
datetime
from
decimal
import
Decimal
,
DecimalException
import
inspect
import
re
import
warnings
from
decimal
import
Decimal
,
DecimalException
from
django
import
forms
from
django.core
import
validators
from
django.core.exceptions
import
ValidationError
from
django.conf
import
settings
from
django.db.models.fields
import
BLANK_CHOICE_DASH
from
django
import
forms
from
django.forms
import
widgets
from
django.utils.encoding
import
is_protected_type
from
django.utils.translation
import
ugettext_lazy
as
_
from
django.utils.datastructures
import
SortedDict
from
rest_framework
import
ISO_8601
from
rest_framework.compat
import
(
timezone
,
parse_date
,
parse_datetime
,
parse_time
)
from
rest_framework.compat
import
BytesIO
from
rest_framework.compat
import
six
from
rest_framework.compat
import
smart_text
,
force_text
,
is_non_str_iterable
from
rest_framework.compat
import
(
timezone
,
parse_date
,
parse_datetime
,
parse_time
,
BytesIO
,
six
,
smart_text
,
force_text
,
is_non_str_iterable
)
from
rest_framework.settings
import
api_settings
...
...
@@ -256,6 +255,12 @@ class WritableField(Field):
widget
=
widget
()
self
.
widget
=
widget
def
__deepcopy__
(
self
,
memo
):
result
=
copy
.
copy
(
self
)
memo
[
id
(
self
)]
=
result
result
.
validators
=
self
.
validators
[:]
return
result
def
validate
(
self
,
value
):
if
value
in
validators
.
EMPTY_VALUES
and
self
.
required
:
raise
ValidationError
(
self
.
error_messages
[
'required'
])
...
...
@@ -428,13 +433,6 @@ class SlugField(CharField):
def
__init__
(
self
,
*
args
,
**
kwargs
):
super
(
SlugField
,
self
)
.
__init__
(
*
args
,
**
kwargs
)
def
__deepcopy__
(
self
,
memo
):
result
=
copy
.
copy
(
self
)
memo
[
id
(
self
)]
=
result
#result.widget = copy.deepcopy(self.widget, memo)
result
.
validators
=
self
.
validators
[:]
return
result
class
ChoiceField
(
WritableField
):
type_name
=
'ChoiceField'
...
...
@@ -503,13 +501,6 @@ class EmailField(CharField):
return
None
return
ret
.
strip
()
def
__deepcopy__
(
self
,
memo
):
result
=
copy
.
copy
(
self
)
memo
[
id
(
self
)]
=
result
#result.widget = copy.deepcopy(self.widget, memo)
result
.
validators
=
self
.
validators
[:]
return
result
class
RegexField
(
CharField
):
type_name
=
'RegexField'
...
...
@@ -534,12 +525,6 @@ class RegexField(CharField):
regex
=
property
(
_get_regex
,
_set_regex
)
def
__deepcopy__
(
self
,
memo
):
result
=
copy
.
copy
(
self
)
memo
[
id
(
self
)]
=
result
result
.
validators
=
self
.
validators
[:]
return
result
class
DateField
(
WritableField
):
type_name
=
'DateField'
...
...
rest_framework/views.py
View file @
40e09472
...
...
@@ -341,8 +341,15 @@ class APIView(View):
Return a dictionary of metadata about the view.
Used to return responses for OPTIONS requests.
"""
# This is used by ViewSets to disambiguate instance vs list views
view_name_suffix
=
getattr
(
self
,
'suffix'
,
None
)
# By default we can't provide any form-like information, however the
# generic views override this implementation and add additional
# information for POST and PUT methods, based on the serializer.
ret
=
SortedDict
()
ret
[
'name'
]
=
get_view_name
(
self
.
__class__
)
ret
[
'name'
]
=
get_view_name
(
self
.
__class__
,
view_name_suffix
)
ret
[
'description'
]
=
get_view_description
(
self
.
__class__
)
ret
[
'renders'
]
=
[
renderer
.
media_type
for
renderer
in
self
.
renderer_classes
]
ret
[
'parses'
]
=
[
parser
.
media_type
for
parser
in
self
.
parser_classes
]
...
...
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