X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/4fae06ea1b9fec1a45482ac043aa049ebce3f465..ac5de8695878cb6aabf9161930af189cf5d15316:/src/cover/forms.py?ds=sidebyside diff --git a/src/cover/forms.py b/src/cover/forms.py index 7a855940..a1ba182d 100644 --- a/src/cover/forms.py +++ b/src/cover/forms.py @@ -77,16 +77,21 @@ class ImageEditForm(forms.ModelForm): """Form used for editing a Book.""" class Meta: model = Image - exclude = ['download_url'] + exclude = ['download_url', 'use_file', 'example',] + + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self.fields['file'].required = False def clean(self): cleaned_data = super(ImageEditForm, self).clean() uploaded_file = cleaned_data.get('file', None) - width, height = PILImage.open(uploaded_file.file).size - min_width, min_height = settings.MIN_COVER_SIZE - if width < min_width or height < min_height: - raise forms.ValidationError(gettext('Image too small: %sx%s, minimal dimensions %sx%s') % - (width, height, min_width, min_height)) + if uploaded_file is not None: + width, height = PILImage.open(uploaded_file.file).size + min_width, min_height = settings.MIN_COVER_SIZE + if width < min_width or height < min_height: + raise forms.ValidationError(gettext('Image too small: %sx%s, minimal dimensions %sx%s') % + (width, height, min_width, min_height)) class ReadonlyImageEditForm(ImageEditForm):