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
a1397ac6
Commit
a1397ac6
authored
Jul 19, 2015
by
Aider Ibragimov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix bugs, move version branching to compat, update ModelSerializer mapping
parent
d8451579
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
26 additions
and
11 deletions
+26
-11
rest_framework/compat.py
+19
-0
rest_framework/fields.py
+5
-11
rest_framework/filters.py
+1
-0
rest_framework/serializers.py
+1
-0
No files found.
rest_framework/compat.py
View file @
a1397ac6
...
@@ -12,6 +12,7 @@ import django
...
@@ -12,6 +12,7 @@ import django
from
django.conf
import
settings
from
django.conf
import
settings
from
django.core.exceptions
import
ImproperlyConfigured
from
django.core.exceptions
import
ImproperlyConfigured
from
django.db
import
connection
,
transaction
from
django.db
import
connection
,
transaction
from
django.forms
import
FilePathField
as
DjangoFilePathField
from
django.test.client
import
FakePayload
from
django.test.client
import
FakePayload
from
django.utils
import
six
from
django.utils
import
six
from
django.utils.encoding
import
force_text
from
django.utils.encoding
import
force_text
...
@@ -291,3 +292,21 @@ def set_rollback():
...
@@ -291,3 +292,21 @@ def set_rollback():
else
:
else
:
# transaction not managed
# transaction not managed
pass
pass
def
get_filepathfield
(
path
,
match
=
None
,
recursive
=
False
,
allow_files
=
True
,
allow_folders
=
False
,
required
=
None
):
"""Create proper Django FilePathField with allowed kwargs."""
if
django
.
VERSION
<
(
1
,
5
):
# django field doesn't have allow_folders, allow_files kwargs
field
=
DjangoFilePathField
(
path
,
match
=
match
,
recursive
=
recursive
,
required
=
required
)
else
:
field
=
DjangoFilePathField
(
path
,
match
=
match
,
recursive
=
recursive
,
allow_files
=
allow_files
,
allow_folders
=
allow_folders
,
required
=
required
)
return
field
rest_framework/fields.py
View file @
a1397ac6
...
@@ -26,7 +26,7 @@ from rest_framework import ISO_8601
...
@@ -26,7 +26,7 @@ from rest_framework import ISO_8601
from
rest_framework.compat
import
(
from
rest_framework.compat
import
(
EmailValidator
,
MaxLengthValidator
,
MaxValueValidator
,
MinLengthValidator
,
EmailValidator
,
MaxLengthValidator
,
MaxValueValidator
,
MinLengthValidator
,
MinValueValidator
,
OrderedDict
,
URLValidator
,
duration_string
,
MinValueValidator
,
OrderedDict
,
URLValidator
,
duration_string
,
parse_duration
,
unicode_repr
,
unicode_to_repr
parse_duration
,
unicode_repr
,
unicode_to_repr
,
get_filepathfield
)
)
from
rest_framework.exceptions
import
ValidationError
from
rest_framework.exceptions
import
ValidationError
from
rest_framework.settings
import
api_settings
from
rest_framework.settings
import
api_settings
...
@@ -717,16 +717,10 @@ class FilePathField(CharField):
...
@@ -717,16 +717,10 @@ class FilePathField(CharField):
super
(
FilePathField
,
self
)
.
__init__
(
**
kwargs
)
super
(
FilePathField
,
self
)
.
__init__
(
**
kwargs
)
# create field and get options to avoid code duplication
# create field and get options to avoid code duplication
if
django
.
VERSION
<
(
1
,
5
):
field
=
get_filepathfield
(
# django field doesn't have allow_folders, allow_files kwargs
path
,
match
=
match
,
recursive
=
recursive
,
allow_files
=
allow_files
,
field
=
DjangoFilePathField
(
allow_folders
=
allow_folders
,
required
=
required
path
,
match
=
match
,
recursive
=
recursive
,
required
=
required
)
)
else
:
field
=
DjangoFilePathField
(
path
,
match
=
match
,
recursive
=
recursive
,
allow_files
=
allow_files
,
allow_folders
=
allow_folders
,
required
=
required
)
self
.
choices
=
OrderedDict
(
field
.
choices
)
self
.
choices
=
OrderedDict
(
field
.
choices
)
self
.
choice_strings_to_values
=
dict
([
self
.
choice_strings_to_values
=
dict
([
...
...
rest_framework/filters.py
View file @
a1397ac6
...
@@ -191,6 +191,7 @@ class DjangoObjectPermissionsFilter(BaseFilterBackend):
...
@@ -191,6 +191,7 @@ class DjangoObjectPermissionsFilter(BaseFilterBackend):
perm_format
=
'
%(app_label)
s.view_
%(model_name)
s'
perm_format
=
'
%(app_label)
s.view_
%(model_name)
s'
def
filter_queryset
(
self
,
request
,
queryset
,
view
):
def
filter_queryset
(
self
,
request
,
queryset
,
view
):
extra
=
{}
user
=
request
.
user
user
=
request
.
user
model_cls
=
queryset
.
model
model_cls
=
queryset
.
model
kwargs
=
{
kwargs
=
{
...
...
rest_framework/serializers.py
View file @
a1397ac6
...
@@ -773,6 +773,7 @@ class ModelSerializer(Serializer):
...
@@ -773,6 +773,7 @@ class ModelSerializer(Serializer):
models
.
TimeField
:
TimeField
,
models
.
TimeField
:
TimeField
,
models
.
URLField
:
URLField
,
models
.
URLField
:
URLField
,
models
.
GenericIPAddressField
:
IPAddressField
,
models
.
GenericIPAddressField
:
IPAddressField
,
models
.
FilePathField
:
FilePathField
,
}
}
if
ModelDurationField
is
not
None
:
if
ModelDurationField
is
not
None
:
serializer_field_mapping
[
ModelDurationField
]
=
DurationField
serializer_field_mapping
[
ModelDurationField
]
=
DurationField
...
...
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