Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
flask-admin
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Python-Dev
flask-admin
Commits
1a883db4
Commit
1a883db4
authored
Jul 08, 2015
by
Serge S. Koval
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed #934 - Upload field fixes
parent
a03e3c76
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
6 deletions
+10
-6
fields.py
flask_admin/form/fields.py
+2
-0
upload.py
flask_admin/form/upload.py
+8
-6
No files found.
flask_admin/form/fields.py
View file @
1a883db4
...
@@ -13,6 +13,7 @@ An understanding of WTForms's Custom Widgets is helpful for understanding this c
...
@@ -13,6 +13,7 @@ An understanding of WTForms's Custom Widgets is helpful for understanding this c
__all__
=
[
'DateTimeField'
,
'TimeField'
,
'Select2Field'
,
'Select2TagsField'
]
__all__
=
[
'DateTimeField'
,
'TimeField'
,
'Select2Field'
,
'Select2TagsField'
]
class
DateTimeField
(
fields
.
DateTimeField
):
class
DateTimeField
(
fields
.
DateTimeField
):
"""
"""
Allows modifying the datetime format of a DateTimeField using form_args.
Allows modifying the datetime format of a DateTimeField using form_args.
...
@@ -35,6 +36,7 @@ class DateTimeField(fields.DateTimeField):
...
@@ -35,6 +36,7 @@ class DateTimeField(fields.DateTimeField):
self
.
format
=
format
or
'
%
Y-
%
m-
%
d
%
H:
%
M:
%
S'
self
.
format
=
format
or
'
%
Y-
%
m-
%
d
%
H:
%
M:
%
S'
class
TimeField
(
fields
.
Field
):
class
TimeField
(
fields
.
Field
):
"""
"""
A text field which stores a `datetime.time` object.
A text field which stores a `datetime.time` object.
...
...
flask_admin/form/upload.py
View file @
1a883db4
...
@@ -203,10 +203,12 @@ class FileUploadField(fields.StringField):
...
@@ -203,10 +203,12 @@ class FileUploadField(fields.StringField):
def
pre_validate
(
self
,
form
):
def
pre_validate
(
self
,
form
):
if
self
.
_is_uploaded_file
(
self
.
data
)
and
not
self
.
is_file_allowed
(
self
.
data
.
filename
):
if
self
.
_is_uploaded_file
(
self
.
data
)
and
not
self
.
is_file_allowed
(
self
.
data
.
filename
):
raise
ValidationError
(
gettext
(
'Invalid file extension'
))
raise
ValidationError
(
gettext
(
'Invalid file extension'
))
# Handle overwriting existing content
# Handle overwriting existing content
if
not
self
.
_is_uploaded_file
(
self
.
data
):
if
not
self
.
_is_uploaded_file
(
self
.
data
):
return
return
if
self
.
_allow_overwrite
==
False
and
os
.
path
.
exists
(
self
.
_get_path
(
self
.
data
.
filename
)):
if
not
self
.
_allow_overwrite
and
os
.
path
.
exists
(
self
.
_get_path
(
self
.
data
.
filename
)):
raise
ValidationError
(
gettext
(
'File "
%
s" already exists.'
%
self
.
data
.
filename
))
raise
ValidationError
(
gettext
(
'File "
%
s" already exists.'
%
self
.
data
.
filename
))
def
process
(
self
,
formdata
,
data
=
unset_value
):
def
process
(
self
,
formdata
,
data
=
unset_value
):
...
@@ -221,10 +223,10 @@ class FileUploadField(fields.StringField):
...
@@ -221,10 +223,10 @@ class FileUploadField(fields.StringField):
if
self
.
_should_delete
:
if
self
.
_should_delete
:
self
.
data
=
None
self
.
data
=
None
elif
valuelist
:
elif
valuelist
:
data
=
valuelist
[
0
]
for
data
in
valuelist
:
if
self
.
_is_uploaded_file
(
data
):
if
self
.
_is_uploaded_file
(
data
):
self
.
data
=
data
self
.
data
=
data
break
def
populate_obj
(
self
,
obj
,
name
):
def
populate_obj
(
self
,
obj
,
name
):
field
=
getattr
(
obj
,
name
,
None
)
field
=
getattr
(
obj
,
name
,
None
)
...
@@ -338,7 +340,7 @@ class ImageUploadField(FileUploadField):
...
@@ -338,7 +340,7 @@ class ImageUploadField(FileUploadField):
:param max_size:
:param max_size:
Tuple of (width, height, force) or None. If provided, Flask-Admin will
Tuple of (width, height, force) or None. If provided, Flask-Admin will
resize image to the desired size.
resize image to the desired size.
Width and height is in pixels. If `force` is set to `True`, will try to fit image into dimensions and
Width and height is in pixels. If `force` is set to `True`, will try to fit image into dimensions and
keep aspect ratio, otherwise will just resize to target size.
keep aspect ratio, otherwise will just resize to target size.
:param thumbgen:
:param thumbgen:
...
...
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