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
c35b9eb0
Commit
c35b9eb0
authored
Nov 14, 2012
by
Marko Tibold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Processed review comments.
No type checking in .restore_fields() Added missing BytesIO import.
parent
8cdbc0a3
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
10 deletions
+17
-10
rest_framework/fields.py
+16
-6
rest_framework/serializers.py
+1
-4
No files found.
rest_framework/fields.py
View file @
c35b9eb0
...
...
@@ -3,6 +3,8 @@ import datetime
import
inspect
import
warnings
from
io
import
BytesIO
from
django.core
import
validators
from
django.core.exceptions
import
ObjectDoesNotExist
,
ValidationError
from
django.core.urlresolvers
import
resolve
,
get_script_prefix
...
...
@@ -31,6 +33,7 @@ class Field(object):
creation_counter
=
0
empty
=
''
type_name
=
None
_use_files
=
None
def
__init__
(
self
,
source
=
None
):
self
.
parent
=
None
...
...
@@ -51,7 +54,7 @@ class Field(object):
self
.
root
=
parent
.
root
or
parent
self
.
context
=
self
.
root
.
context
def
field_from_native
(
self
,
data
,
field_name
,
into
):
def
field_from_native
(
self
,
data
,
fi
les
,
fi
eld_name
,
into
):
"""
Given a dictionary and a field name, updates the dictionary `into`,
with the field and it's deserialized value.
...
...
@@ -166,7 +169,7 @@ class WritableField(Field):
if
errors
:
raise
ValidationError
(
errors
)
def
field_from_native
(
self
,
data
,
field_name
,
into
):
def
field_from_native
(
self
,
data
,
fi
les
,
fi
eld_name
,
into
):
"""
Given a dictionary and a field name, updates the dictionary `into`,
with the field and it's deserialized value.
...
...
@@ -175,7 +178,10 @@ class WritableField(Field):
return
try
:
native
=
data
[
field_name
]
if
self
.
_use_files
:
native
=
files
[
field_name
]
else
:
native
=
data
[
field_name
]
except
KeyError
:
if
self
.
default
is
not
None
:
native
=
self
.
default
...
...
@@ -323,7 +329,7 @@ class RelatedField(WritableField):
value
=
getattr
(
obj
,
self
.
source
or
field_name
)
return
self
.
to_native
(
value
)
def
field_from_native
(
self
,
data
,
field_name
,
into
):
def
field_from_native
(
self
,
data
,
fi
les
,
fi
eld_name
,
into
):
if
self
.
read_only
:
return
...
...
@@ -341,7 +347,7 @@ class ManyRelatedMixin(object):
value
=
getattr
(
obj
,
self
.
source
or
field_name
)
return
[
self
.
to_native
(
item
)
for
item
in
value
.
all
()]
def
field_from_native
(
self
,
data
,
field_name
,
into
):
def
field_from_native
(
self
,
data
,
fi
les
,
fi
eld_name
,
into
):
if
self
.
read_only
:
return
...
...
@@ -907,8 +913,10 @@ class FloatField(WritableField):
class
FileField
(
WritableField
):
_use_files
=
True
type_name
=
'FileField'
widget
=
widgets
.
FileInput
default_error_messages
=
{
'invalid'
:
_
(
"No file was submitted. Check the encoding type on the form."
),
'missing'
:
_
(
"No file was submitted."
),
...
...
@@ -951,6 +959,8 @@ class FileField(WritableField):
class
ImageField
(
FileField
):
_use_files
=
True
default_error_messages
=
{
'invalid_image'
:
_
(
"Upload a valid image. The file you uploaded was either not an image or a corrupted image."
),
}
...
...
@@ -990,7 +1000,7 @@ class ImageField(FileField):
# _imaging C module isn't available, so an ImportError will be
# raised. Catch and re-raise.
raise
except
Exception
:
# Python Imaging Library doesn't recognize it as an image
except
Exception
:
# Python Imaging Library doesn't recognize it as an image
raise
ValidationError
(
self
.
error_messages
[
'invalid_image'
])
if
hasattr
(
f
,
'seek'
)
and
callable
(
f
.
seek
):
f
.
seek
(
0
)
...
...
rest_framework/serializers.py
View file @
c35b9eb0
...
...
@@ -198,10 +198,7 @@ class BaseSerializer(Field):
reverted_data
=
{}
for
field_name
,
field
in
fields
.
items
():
try
:
if
isinstance
(
field
,
(
FileField
,
ImageField
)):
field
.
field_from_native
(
files
,
field_name
,
reverted_data
)
else
:
field
.
field_from_native
(
data
,
field_name
,
reverted_data
)
field
.
field_from_native
(
data
,
files
,
field_name
,
reverted_data
)
except
ValidationError
as
err
:
self
.
_errors
[
field_name
]
=
list
(
err
.
messages
)
...
...
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