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
49f87cfb
Commit
49f87cfb
authored
Oct 29, 2012
by
Tom Christie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Deal with None and missing values
parent
dfcb560f
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
7 deletions
+14
-7
rest_framework/fields.py
+14
-7
No files found.
rest_framework/fields.py
View file @
49f87cfb
...
@@ -509,7 +509,10 @@ class EmailField(CharField):
...
@@ -509,7 +509,10 @@ class EmailField(CharField):
default_validators
=
[
validators
.
validate_email
]
default_validators
=
[
validators
.
validate_email
]
def
from_native
(
self
,
value
):
def
from_native
(
self
,
value
):
return
super
(
EmailField
,
self
)
.
from_native
(
value
)
.
strip
()
ret
=
super
(
EmailField
,
self
)
.
from_native
(
value
)
if
ret
is
None
:
return
None
return
ret
.
strip
()
def
__deepcopy__
(
self
,
memo
):
def
__deepcopy__
(
self
,
memo
):
result
=
copy
.
copy
(
self
)
result
=
copy
.
copy
(
self
)
...
@@ -531,8 +534,9 @@ class DateField(WritableField):
...
@@ -531,8 +534,9 @@ class DateField(WritableField):
empty
=
None
empty
=
None
def
from_native
(
self
,
value
):
def
from_native
(
self
,
value
):
if
value
is
None
:
if
value
in
validators
.
EMPTY_VALUES
:
return
value
return
None
if
isinstance
(
value
,
datetime
.
datetime
):
if
isinstance
(
value
,
datetime
.
datetime
):
if
timezone
and
settings
.
USE_TZ
and
timezone
.
is_aware
(
value
):
if
timezone
and
settings
.
USE_TZ
and
timezone
.
is_aware
(
value
):
# Convert aware datetimes to the default time zone
# Convert aware datetimes to the default time zone
...
@@ -570,8 +574,9 @@ class DateTimeField(WritableField):
...
@@ -570,8 +574,9 @@ class DateTimeField(WritableField):
empty
=
None
empty
=
None
def
from_native
(
self
,
value
):
def
from_native
(
self
,
value
):
if
value
is
None
:
if
value
in
validators
.
EMPTY_VALUES
:
return
value
return
None
if
isinstance
(
value
,
datetime
.
datetime
):
if
isinstance
(
value
,
datetime
.
datetime
):
return
value
return
value
if
isinstance
(
value
,
datetime
.
date
):
if
isinstance
(
value
,
datetime
.
date
):
...
@@ -629,6 +634,7 @@ class IntegerField(WritableField):
...
@@ -629,6 +634,7 @@ class IntegerField(WritableField):
def
from_native
(
self
,
value
):
def
from_native
(
self
,
value
):
if
value
in
validators
.
EMPTY_VALUES
:
if
value
in
validators
.
EMPTY_VALUES
:
return
None
return
None
try
:
try
:
value
=
int
(
str
(
value
))
value
=
int
(
str
(
value
))
except
(
ValueError
,
TypeError
):
except
(
ValueError
,
TypeError
):
...
@@ -644,8 +650,9 @@ class FloatField(WritableField):
...
@@ -644,8 +650,9 @@ class FloatField(WritableField):
}
}
def
from_native
(
self
,
value
):
def
from_native
(
self
,
value
):
if
value
is
None
:
if
value
in
validators
.
EMPTY_VALUES
:
return
value
return
None
try
:
try
:
return
float
(
value
)
return
float
(
value
)
except
(
TypeError
,
ValueError
):
except
(
TypeError
,
ValueError
):
...
...
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