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
ec5badf7
Commit
ec5badf7
authored
Jan 19, 2012
by
Alen Mujezinovic
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Renamed `unknown_form_fields` to `allow_unknown_form_fields`
parent
167dce00
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
6 additions
and
6 deletions
+6
-6
djangorestframework/resources.py
+4
-4
djangorestframework/tests/validators.py
+2
-2
No files found.
djangorestframework/resources.py
View file @
ec5badf7
...
@@ -78,7 +78,7 @@ class FormResource(Resource):
...
@@ -78,7 +78,7 @@ class FormResource(Resource):
This can be overridden by a :attr:`form` attribute on the :class:`views.View`.
This can be overridden by a :attr:`form` attribute on the :class:`views.View`.
"""
"""
unknown_form_fields
=
False
allow_
unknown_form_fields
=
False
"""
"""
Flag to check for unknown fields when validating a form. If set to false and
Flag to check for unknown fields when validating a form. If set to false and
we receive request data that is not expected by the form it raises an
we receive request data that is not expected by the form it raises an
...
@@ -93,7 +93,7 @@ class FormResource(Resource):
...
@@ -93,7 +93,7 @@ class FormResource(Resource):
Raises a :exc:`response.ErrorResponse` with status code 400 (Bad Request) on failure.
Raises a :exc:`response.ErrorResponse` with status code 400 (Bad Request) on failure.
Validation is standard form validation, with an additional constraint that *no extra unknown fields* may be supplied
Validation is standard form validation, with an additional constraint that *no extra unknown fields* may be supplied
if :attr:`self.unknown_form_fields` is ``False``.
if :attr:`self.
allow_
unknown_form_fields` is ``False``.
On failure the :exc:`response.ErrorResponse` content is a dict which may contain :obj:`'errors'` and :obj:`'field-errors'` keys.
On failure the :exc:`response.ErrorResponse` content is a dict which may contain :obj:`'errors'` and :obj:`'field-errors'` keys.
If the :obj:`'errors'` key exists it is a list of strings of non-field errors.
If the :obj:`'errors'` key exists it is a list of strings of non-field errors.
...
@@ -141,7 +141,7 @@ class FormResource(Resource):
...
@@ -141,7 +141,7 @@ class FormResource(Resource):
unknown_fields
=
unknown_fields
-
set
((
'csrfmiddlewaretoken'
,
'_accept'
,
'_method'
))
# TODO: Ugh.
unknown_fields
=
unknown_fields
-
set
((
'csrfmiddlewaretoken'
,
'_accept'
,
'_method'
))
# TODO: Ugh.
# Check using both regular validation, and our stricter no additional fields rule
# Check using both regular validation, and our stricter no additional fields rule
if
bound_form
.
is_valid
()
and
(
self
.
unknown_form_fields
or
not
unknown_fields
):
if
bound_form
.
is_valid
()
and
(
self
.
allow_
unknown_form_fields
or
not
unknown_fields
):
# Validation succeeded...
# Validation succeeded...
cleaned_data
=
bound_form
.
cleaned_data
cleaned_data
=
bound_form
.
cleaned_data
...
@@ -398,7 +398,7 @@ class ModelResource(FormResource):
...
@@ -398,7 +398,7 @@ class ModelResource(FormResource):
"""
"""
model_fields
=
set
(
field
.
name
for
field
in
self
.
model
.
_meta
.
fields
)
model_fields
=
set
(
field
.
name
for
field
in
self
.
model
.
_meta
.
fields
)
if
fields
:
if
model_
fields
:
return
model_fields
&
set
(
as_tuple
(
self
.
fields
))
return
model_fields
&
set
(
as_tuple
(
self
.
fields
))
return
model_fields
-
set
(
as_tuple
(
self
.
exclude
))
return
model_fields
-
set
(
as_tuple
(
self
.
exclude
))
...
...
djangorestframework/tests/validators.py
View file @
ec5badf7
...
@@ -142,9 +142,9 @@ class TestFormValidation(TestCase):
...
@@ -142,9 +142,9 @@ class TestFormValidation(TestCase):
"""If we set ``unknown_form_fields`` on the form resource, then don't
"""If we set ``unknown_form_fields`` on the form resource, then don't
raise errors on unexpected request data"""
raise errors on unexpected request data"""
content
=
{
'qwerty'
:
'uiop'
,
'extra'
:
'extra'
}
content
=
{
'qwerty'
:
'uiop'
,
'extra'
:
'extra'
}
validator
.
unknown_form_fields
=
True
validator
.
allow_
unknown_form_fields
=
True
self
.
assertDictEqual
({
'qwerty'
:
u'uiop'
},
validator
.
validate_request
(
content
,
None
),
"Resource didn't accept unknown fields."
)
self
.
assertDictEqual
({
'qwerty'
:
u'uiop'
},
validator
.
validate_request
(
content
,
None
),
"Resource didn't accept unknown fields."
)
validator
.
unknown_form_fields
=
False
validator
.
allow_
unknown_form_fields
=
False
def
validation_does_not_require_extra_fields_if_explicitly_set
(
self
,
validator
):
def
validation_does_not_require_extra_fields_if_explicitly_set
(
self
,
validator
):
"""If we include an allowed_extra_fields paramater on _validate, then do not fail if we do not have fields with those names."""
"""If we include an allowed_extra_fields paramater on _validate, then do not fail if we do not have fields with those names."""
...
...
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