Commit 99f09f5b authored by Serge S. Koval's avatar Serge S. Koval

Do not create thumbnail automatically

parent b1316509
......@@ -39,6 +39,7 @@ class File(db.Model):
def __unicode__(self):
return self.name
class Image(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.Unicode(64))
......@@ -75,6 +76,7 @@ def del_image(mapper, connection, target):
except OSError:
pass
# Administrative views
class FileView(sqla.ModelView):
# Override form field to use Flask-Admin FileUploadField
......@@ -106,7 +108,9 @@ class ImageView(sqla.ModelView):
# 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.
form_extra_fields = {
'path': form.ImageUploadField('Image', path=file_path)
'path': form.ImageUploadField('Image',
path=file_path,
thumbnail_size=(100, 100, True))
}
......
......@@ -257,7 +257,7 @@ class ImageUploadField(FileUploadField):
upload = ImageUploadField('File', thumbgen=prefix_name)
: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
keep aspect ratio, otherwise will just resize to target size.
......@@ -269,7 +269,7 @@ class ImageUploadField(FileUploadField):
raise Exception('PIL library was not found')
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.image = None
......
......@@ -161,4 +161,4 @@ def test_image_upload_field():
eq_(dummy.upload, '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')))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment