Commit 1a883db4 authored by Serge S. Koval's avatar Serge S. Koval

Fixed #934 - Upload field fixes

parent a03e3c76
...@@ -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.
......
...@@ -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:
......
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