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
99f09f5b
Commit
99f09f5b
authored
Jul 28, 2013
by
Serge S. Koval
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Do not create thumbnail automatically
parent
b1316509
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
8 additions
and
4 deletions
+8
-4
simple.py
examples/forms/simple.py
+5
-1
upload.py
flask_admin/form/upload.py
+2
-2
test_form_upload.py
flask_admin/tests/test_form_upload.py
+1
-1
No files found.
examples/forms/simple.py
View file @
99f09f5b
...
@@ -39,6 +39,7 @@ class File(db.Model):
...
@@ -39,6 +39,7 @@ class File(db.Model):
def
__unicode__
(
self
):
def
__unicode__
(
self
):
return
self
.
name
return
self
.
name
class
Image
(
db
.
Model
):
class
Image
(
db
.
Model
):
id
=
db
.
Column
(
db
.
Integer
,
primary_key
=
True
)
id
=
db
.
Column
(
db
.
Integer
,
primary_key
=
True
)
name
=
db
.
Column
(
db
.
Unicode
(
64
))
name
=
db
.
Column
(
db
.
Unicode
(
64
))
...
@@ -75,6 +76,7 @@ def del_image(mapper, connection, target):
...
@@ -75,6 +76,7 @@ def del_image(mapper, connection, target):
except
OSError
:
except
OSError
:
pass
pass
# Administrative views
# Administrative views
class
FileView
(
sqla
.
ModelView
):
class
FileView
(
sqla
.
ModelView
):
# Override form field to use Flask-Admin FileUploadField
# Override form field to use Flask-Admin FileUploadField
...
@@ -106,7 +108,9 @@ class ImageView(sqla.ModelView):
...
@@ -106,7 +108,9 @@ class ImageView(sqla.ModelView):
# Alternative way to contribute field is to override it completely.
# Alternative way to contribute field is to override it completely.
# In this case, Flask-Admin won't attempt to merge various parameters for the field.
# In this case, Flask-Admin won't attempt to merge various parameters for the field.
form_extra_fields
=
{
form_extra_fields
=
{
'path'
:
form
.
ImageUploadField
(
'Image'
,
path
=
file_path
)
'path'
:
form
.
ImageUploadField
(
'Image'
,
path
=
file_path
,
thumbnail_size
=
(
100
,
100
,
True
))
}
}
...
...
flask_admin/form/upload.py
View file @
99f09f5b
...
@@ -257,7 +257,7 @@ class ImageUploadField(FileUploadField):
...
@@ -257,7 +257,7 @@ class ImageUploadField(FileUploadField):
upload = ImageUploadField('File', thumbgen=prefix_name)
upload = ImageUploadField('File', thumbgen=prefix_name)
:param thumbnail_size:
:param thumbnail_size:
Tuple or (width, height, force) values. If not provided,
uses `(128, 128, True)` as default value
.
Tuple or (width, height, force) values. If not provided,
thumbnail won't be created
.
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.
...
@@ -269,7 +269,7 @@ class ImageUploadField(FileUploadField):
...
@@ -269,7 +269,7 @@ class ImageUploadField(FileUploadField):
raise
Exception
(
'PIL library was not found'
)
raise
Exception
(
'PIL library was not found'
)
self
.
thumbnail_fn
=
thumbgen
or
thumbgen_filename
self
.
thumbnail_fn
=
thumbgen
or
thumbgen_filename
self
.
thumbnail_size
=
thumbnail_size
or
(
128
,
128
,
True
)
self
.
thumbnail_size
=
thumbnail_size
self
.
endpoint
=
endpoint
self
.
endpoint
=
endpoint
self
.
image
=
None
self
.
image
=
None
...
...
flask_admin/tests/test_form_upload.py
View file @
99f09f5b
...
@@ -161,4 +161,4 @@ def test_image_upload_field():
...
@@ -161,4 +161,4 @@ def test_image_upload_field():
eq_
(
dummy
.
upload
,
'test1.png'
)
eq_
(
dummy
.
upload
,
'test1.png'
)
ok_
(
op
.
exists
(
op
.
join
(
path
,
'test1.png'
)))
ok_
(
op
.
exists
(
op
.
join
(
path
,
'test1.png'
)))
ok_
(
op
.
exists
(
op
.
join
(
path
,
'test1_thumb.jpg'
)))
ok_
(
not
op
.
exists
(
op
.
join
(
path
,
'test1_thumb.jpg'
)))
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