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
e4ac5666
Commit
e4ac5666
authored
Jan 30, 2013
by
Tom Christie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add dprecation warnings
parent
e24d29ec
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
22 deletions
+36
-22
rest_framework/fields.py
+11
-15
rest_framework/relations.py
+25
-7
No files found.
rest_framework/fields.py
View file @
e4ac5666
...
@@ -33,7 +33,7 @@ class Field(object):
...
@@ -33,7 +33,7 @@ class Field(object):
empty
=
''
empty
=
''
type_name
=
None
type_name
=
None
partial
=
False
partial
=
False
_use_files
=
Non
e
use_files
=
Fals
e
form_field_class
=
forms
.
CharField
form_field_class
=
forms
.
CharField
def
__init__
(
self
,
source
=
None
):
def
__init__
(
self
,
source
=
None
):
...
@@ -126,6 +126,13 @@ class WritableField(Field):
...
@@ -126,6 +126,13 @@ class WritableField(Field):
validators
=
[],
error_messages
=
None
,
widget
=
None
,
validators
=
[],
error_messages
=
None
,
widget
=
None
,
default
=
None
,
blank
=
None
):
default
=
None
,
blank
=
None
):
# 'blank' is to be deprecated in favor of 'required'
if
blank
is
not
None
:
warnings
.
warn
(
'The `blank` keyword argument is due to deprecated. '
'Use the `required` keyword argument instead.'
,
PendingDeprecationWarning
,
stacklevel
=
2
)
required
=
not
(
blank
)
super
(
WritableField
,
self
)
.
__init__
(
source
=
source
)
super
(
WritableField
,
self
)
.
__init__
(
source
=
source
)
self
.
read_only
=
read_only
self
.
read_only
=
read_only
...
@@ -143,7 +150,6 @@ class WritableField(Field):
...
@@ -143,7 +150,6 @@ class WritableField(Field):
self
.
validators
=
self
.
default_validators
+
validators
self
.
validators
=
self
.
default_validators
+
validators
self
.
default
=
default
if
default
is
not
None
else
self
.
default
self
.
default
=
default
if
default
is
not
None
else
self
.
default
self
.
blank
=
blank
# Widgets are ony used for HTML forms.
# Widgets are ony used for HTML forms.
widget
=
widget
or
self
.
widget
widget
=
widget
or
self
.
widget
...
@@ -182,7 +188,7 @@ class WritableField(Field):
...
@@ -182,7 +188,7 @@ class WritableField(Field):
return
return
try
:
try
:
if
self
.
_
use_files
:
if
self
.
use_files
:
files
=
files
or
{}
files
=
files
or
{}
native
=
files
[
field_name
]
native
=
files
[
field_name
]
else
:
else
:
...
@@ -289,16 +295,6 @@ class CharField(WritableField):
...
@@ -289,16 +295,6 @@ class CharField(WritableField):
if
max_length
is
not
None
:
if
max_length
is
not
None
:
self
.
validators
.
append
(
validators
.
MaxLengthValidator
(
max_length
))
self
.
validators
.
append
(
validators
.
MaxLengthValidator
(
max_length
))
def
validate
(
self
,
value
):
"""
Validates that the value is supplied (if required).
"""
# if empty string and allow blank
if
self
.
blank
and
not
value
:
return
else
:
super
(
CharField
,
self
)
.
validate
(
value
)
def
from_native
(
self
,
value
):
def
from_native
(
self
,
value
):
if
isinstance
(
value
,
basestring
)
or
value
is
None
:
if
isinstance
(
value
,
basestring
)
or
value
is
None
:
return
value
return
value
...
@@ -567,7 +563,7 @@ class FloatField(WritableField):
...
@@ -567,7 +563,7 @@ class FloatField(WritableField):
class
FileField
(
WritableField
):
class
FileField
(
WritableField
):
_
use_files
=
True
use_files
=
True
type_name
=
'FileField'
type_name
=
'FileField'
form_field_class
=
forms
.
FileField
form_field_class
=
forms
.
FileField
widget
=
widgets
.
FileInput
widget
=
widgets
.
FileInput
...
@@ -611,7 +607,7 @@ class FileField(WritableField):
...
@@ -611,7 +607,7 @@ class FileField(WritableField):
class
ImageField
(
FileField
):
class
ImageField
(
FileField
):
_
use_files
=
True
use_files
=
True
form_field_class
=
forms
.
ImageField
form_field_class
=
forms
.
ImageField
default_error_messages
=
{
default_error_messages
=
{
...
...
rest_framework/relations.py
View file @
e4ac5666
...
@@ -8,6 +8,7 @@ from django.utils.translation import ugettext_lazy as _
...
@@ -8,6 +8,7 @@ from django.utils.translation import ugettext_lazy as _
from
rest_framework.fields
import
Field
,
WritableField
from
rest_framework.fields
import
Field
,
WritableField
from
rest_framework.reverse
import
reverse
from
rest_framework.reverse
import
reverse
from
urlparse
import
urlparse
from
urlparse
import
urlparse
import
warnings
##### Relational fields #####
##### Relational fields #####
...
@@ -26,23 +27,27 @@ class RelatedField(WritableField):
...
@@ -26,23 +27,27 @@ class RelatedField(WritableField):
cache_choices
=
False
cache_choices
=
False
empty_label
=
None
empty_label
=
None
default_read_only
=
True
# TODO: Remove this
read_only
=
True
many
=
False
many
=
False
def
__init__
(
self
,
*
args
,
**
kwargs
):
def
__init__
(
self
,
*
args
,
**
kwargs
):
# 'null'
will
be deprecated in favor of 'required'
# 'null'
is to
be deprecated in favor of 'required'
if
'null'
in
kwargs
:
if
'null'
in
kwargs
:
warnings
.
warn
(
'The `null` keyword argument is due to be deprecated. '
'Use the `required` keyword argument instead.'
,
PendingDeprecationWarning
,
stacklevel
=
2
)
kwargs
[
'required'
]
=
not
kwargs
.
pop
(
'null'
)
kwargs
[
'required'
]
=
not
kwargs
.
pop
(
'null'
)
self
.
queryset
=
kwargs
.
pop
(
'queryset'
,
None
)
self
.
queryset
=
kwargs
.
pop
(
'queryset'
,
None
)
self
.
many
=
kwargs
.
pop
(
'many'
,
self
.
many
)
self
.
many
=
kwargs
.
pop
(
'many'
,
self
.
many
)
super
(
RelatedField
,
self
)
.
__init__
(
*
args
,
**
kwargs
)
self
.
read_only
=
kwargs
.
pop
(
'read_only'
,
self
.
default_read_only
)
if
self
.
many
:
if
self
.
many
:
self
.
widget
=
self
.
many_widget
self
.
widget
=
self
.
many_widget
self
.
form_field_class
=
self
.
many_form_field_class
self
.
form_field_class
=
self
.
many_form_field_class
kwargs
[
'read_only'
]
=
kwargs
.
pop
(
'read_only'
,
self
.
read_only
)
super
(
RelatedField
,
self
)
.
__init__
(
*
args
,
**
kwargs
)
def
initialize
(
self
,
parent
,
field_name
):
def
initialize
(
self
,
parent
,
field_name
):
super
(
RelatedField
,
self
)
.
initialize
(
parent
,
field_name
)
super
(
RelatedField
,
self
)
.
initialize
(
parent
,
field_name
)
if
self
.
queryset
is
None
and
not
self
.
read_only
:
if
self
.
queryset
is
None
and
not
self
.
read_only
:
...
@@ -157,7 +162,7 @@ class PrimaryKeyRelatedField(RelatedField):
...
@@ -157,7 +162,7 @@ class PrimaryKeyRelatedField(RelatedField):
"""
"""
Represents a relationship as a pk value.
Represents a relationship as a pk value.
"""
"""
default_
read_only
=
False
read_only
=
False
default_error_messages
=
{
default_error_messages
=
{
'does_not_exist'
:
_
(
"Invalid pk '
%
s' - object does not exist."
),
'does_not_exist'
:
_
(
"Invalid pk '
%
s' - object does not exist."
),
...
@@ -231,7 +236,7 @@ class SlugRelatedField(RelatedField):
...
@@ -231,7 +236,7 @@ class SlugRelatedField(RelatedField):
"""
"""
Represents a relationship using a unique field on the target.
Represents a relationship using a unique field on the target.
"""
"""
default_
read_only
=
False
read_only
=
False
default_error_messages
=
{
default_error_messages
=
{
'does_not_exist'
:
_
(
"Object with
%
s=
%
s does not exist."
),
'does_not_exist'
:
_
(
"Object with
%
s=
%
s does not exist."
),
...
@@ -269,7 +274,7 @@ class HyperlinkedRelatedField(RelatedField):
...
@@ -269,7 +274,7 @@ class HyperlinkedRelatedField(RelatedField):
pk_url_kwarg
=
'pk'
pk_url_kwarg
=
'pk'
slug_field
=
'slug'
slug_field
=
'slug'
slug_url_kwarg
=
None
# Defaults to same as `slug_field` unless overridden
slug_url_kwarg
=
None
# Defaults to same as `slug_field` unless overridden
default_
read_only
=
False
read_only
=
False
default_error_messages
=
{
default_error_messages
=
{
'no_match'
:
_
(
'Invalid hyperlink - No URL match'
),
'no_match'
:
_
(
'Invalid hyperlink - No URL match'
),
...
@@ -390,6 +395,7 @@ class HyperlinkedIdentityField(Field):
...
@@ -390,6 +395,7 @@ class HyperlinkedIdentityField(Field):
pk_url_kwarg
=
'pk'
pk_url_kwarg
=
'pk'
slug_field
=
'slug'
slug_field
=
'slug'
slug_url_kwarg
=
None
# Defaults to same as `slug_field` unless overridden
slug_url_kwarg
=
None
# Defaults to same as `slug_field` unless overridden
read_only
=
True
def
__init__
(
self
,
*
args
,
**
kwargs
):
def
__init__
(
self
,
*
args
,
**
kwargs
):
# TODO: Make view_name mandatory, and have the
# TODO: Make view_name mandatory, and have the
...
@@ -452,23 +458,35 @@ class HyperlinkedIdentityField(Field):
...
@@ -452,23 +458,35 @@ class HyperlinkedIdentityField(Field):
class
ManyRelatedField
(
RelatedField
):
class
ManyRelatedField
(
RelatedField
):
def
__init__
(
self
,
*
args
,
**
kwargs
):
def
__init__
(
self
,
*
args
,
**
kwargs
):
warnings
.
warn
(
'`ManyRelatedField()` is due to be deprecated. '
'Use `RelatedField(many=True)` instead.'
,
PendingDeprecationWarning
,
stacklevel
=
2
)
kwargs
[
'many'
]
=
True
kwargs
[
'many'
]
=
True
super
(
ManyRelatedField
,
self
)
.
__init__
(
*
args
,
**
kwargs
)
super
(
ManyRelatedField
,
self
)
.
__init__
(
*
args
,
**
kwargs
)
class
ManyPrimaryKeyRelatedField
(
PrimaryKeyRelatedField
):
class
ManyPrimaryKeyRelatedField
(
PrimaryKeyRelatedField
):
def
__init__
(
self
,
*
args
,
**
kwargs
):
def
__init__
(
self
,
*
args
,
**
kwargs
):
warnings
.
warn
(
'`ManyPrimaryKeyRelatedField()` is due to be deprecated. '
'Use `PrimaryKeyRelatedField(many=True)` instead.'
,
PendingDeprecationWarning
,
stacklevel
=
2
)
kwargs
[
'many'
]
=
True
kwargs
[
'many'
]
=
True
super
(
ManyPrimaryKeyRelatedField
,
self
)
.
__init__
(
*
args
,
**
kwargs
)
super
(
ManyPrimaryKeyRelatedField
,
self
)
.
__init__
(
*
args
,
**
kwargs
)
class
ManySlugRelatedField
(
SlugRelatedField
):
class
ManySlugRelatedField
(
SlugRelatedField
):
def
__init__
(
self
,
*
args
,
**
kwargs
):
def
__init__
(
self
,
*
args
,
**
kwargs
):
warnings
.
warn
(
'`ManySlugRelatedField()` is due to be deprecated. '
'Use `SlugRelatedField(many=True)` instead.'
,
PendingDeprecationWarning
,
stacklevel
=
2
)
kwargs
[
'many'
]
=
True
kwargs
[
'many'
]
=
True
super
(
ManySlugRelatedField
,
self
)
.
__init__
(
*
args
,
**
kwargs
)
super
(
ManySlugRelatedField
,
self
)
.
__init__
(
*
args
,
**
kwargs
)
class
ManyHyperlinkedRelatedField
(
HyperlinkedRelatedField
):
class
ManyHyperlinkedRelatedField
(
HyperlinkedRelatedField
):
def
__init__
(
self
,
*
args
,
**
kwargs
):
def
__init__
(
self
,
*
args
,
**
kwargs
):
warnings
.
warn
(
'`ManyHyperlinkedRelatedField()` is due to be deprecated. '
'Use `HyperlinkedRelatedField(many=True)` instead.'
,
PendingDeprecationWarning
,
stacklevel
=
2
)
kwargs
[
'many'
]
=
True
kwargs
[
'many'
]
=
True
super
(
ManyHyperlinkedRelatedField
,
self
)
.
__init__
(
*
args
,
**
kwargs
)
super
(
ManyHyperlinkedRelatedField
,
self
)
.
__init__
(
*
args
,
**
kwargs
)
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