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
18af1811
Commit
18af1811
authored
Aug 13, 2015
by
Tom Christie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix boolean checkboxes setting to False. Closes #3258. Closes #2776.
parent
a3e64fbe
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
10 deletions
+16
-10
rest_framework/fields.py
+1
-3
tests/test_fields.py
+15
-7
No files found.
rest_framework/fields.py
View file @
18af1811
...
...
@@ -280,9 +280,7 @@ class Field(object):
self
.
allow_null
=
allow_null
if
self
.
default_empty_html
is
not
empty
:
if
not
required
:
self
.
default_empty_html
=
empty
elif
default
is
not
empty
:
if
default
is
not
empty
:
self
.
default_empty_html
=
default
if
validators
is
not
None
:
...
...
tests/test_fields.py
View file @
18af1811
...
...
@@ -227,19 +227,27 @@ class TestInvalidErrorKey:
class
TestBooleanHTMLInput
:
def
setup
(
self
):
def
test_empty_html_checkbox
(
self
):
"""
HTML checkboxes do not send any value, but should be treated
as `False` by BooleanField.
"""
class
TestSerializer
(
serializers
.
Serializer
):
archived
=
serializers
.
BooleanField
()
self
.
Serializer
=
TestSerializer
def
test_empty_html_checkbox
(
self
):
serializer
=
TestSerializer
(
data
=
QueryDict
(
''
))
assert
serializer
.
is_valid
()
assert
serializer
.
validated_data
==
{
'archived'
:
False
}
def
test_empty_html_checkbox_not_required
(
self
):
"""
HTML checkboxes do not send any value, but should be treated
as `False` by BooleanField.
as `False` by BooleanField
, even if the field is required=False
.
"""
# This class mocks up a dictionary like object, that behaves
# as if it was returned for multipart or urlencoded data.
serializer
=
self
.
Serializer
(
data
=
QueryDict
(
''
))
class
TestSerializer
(
serializers
.
Serializer
):
archived
=
serializers
.
BooleanField
(
required
=
False
)
serializer
=
TestSerializer
(
data
=
QueryDict
(
''
))
assert
serializer
.
is_valid
()
assert
serializer
.
validated_data
==
{
'archived'
:
False
}
...
...
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