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
bf35906d
Commit
bf35906d
authored
Aug 03, 2015
by
Tom Christie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
FilePathField subclassing from ChoiceField
parent
877e964d
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
36 deletions
+17
-36
rest_framework/fields.py
+17
-36
No files found.
rest_framework/fields.py
View file @
bf35906d
...
@@ -705,42 +705,6 @@ class IPAddressField(CharField):
...
@@ -705,42 +705,6 @@ class IPAddressField(CharField):
return
super
(
IPAddressField
,
self
)
.
to_internal_value
(
data
)
return
super
(
IPAddressField
,
self
)
.
to_internal_value
(
data
)
class
FilePathField
(
CharField
):
default_error_messages
=
{
'invalid_choice'
:
_
(
'"{input}" is not a valid path choice.'
)
}
def
__init__
(
self
,
path
,
match
=
None
,
recursive
=
False
,
allow_files
=
True
,
allow_folders
=
False
,
required
=
None
,
**
kwargs
):
super
(
FilePathField
,
self
)
.
__init__
(
**
kwargs
)
# Defer to Django's FilePathField implmentation to get the
# valid set of choices.
field
=
DjangoFilePathField
(
path
,
match
=
match
,
recursive
=
recursive
,
allow_files
=
allow_files
,
allow_folders
=
allow_folders
,
required
=
required
)
self
.
choices
=
OrderedDict
(
field
.
choices
)
self
.
choice_strings_to_values
=
dict
([
(
six
.
text_type
(
key
),
key
)
for
key
in
self
.
choices
.
keys
()
])
def
to_internal_value
(
self
,
data
):
if
data
==
''
and
self
.
allow_blank
:
return
''
try
:
return
self
.
choice_strings_to_values
[
six
.
text_type
(
data
)]
except
KeyError
:
self
.
fail
(
'invalid_choice'
,
input
=
data
)
def
to_representation
(
self
,
value
):
if
value
in
(
''
,
None
):
return
value
return
self
.
choice_strings_to_values
[
six
.
text_type
(
value
)]
# Number types...
# Number types...
class
IntegerField
(
Field
):
class
IntegerField
(
Field
):
...
@@ -1215,6 +1179,23 @@ class MultipleChoiceField(ChoiceField):
...
@@ -1215,6 +1179,23 @@ class MultipleChoiceField(ChoiceField):
])
])
class
FilePathField
(
ChoiceField
):
default_error_messages
=
{
'invalid_choice'
:
_
(
'"{input}" is not a valid path choice.'
)
}
def
__init__
(
self
,
path
,
match
=
None
,
recursive
=
False
,
allow_files
=
True
,
allow_folders
=
False
,
required
=
None
,
**
kwargs
):
# Defer to Django's FilePathField implmentation to get the
# valid set of choices.
field
=
DjangoFilePathField
(
path
,
match
=
match
,
recursive
=
recursive
,
allow_files
=
allow_files
,
allow_folders
=
allow_folders
,
required
=
required
)
kwargs
[
'choices'
]
=
field
.
choices
super
(
FilePathField
,
self
)
.
__init__
(
**
kwargs
)
# File types...
# File types...
class
FileField
(
Field
):
class
FileField
(
Field
):
...
...
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