From: Jan Szejko Date: Wed, 1 Feb 2017 16:06:45 +0000 (+0100) Subject: validate cover format on document create X-Git-Url: https://git.mdrn.pl/redakcja.git/commitdiff_plain/b7cdf38bdc5fbff4a13a7cf1aa4f3ff1b7232368?ds=sidebyside;hp=749077f0cfbde180bac85b141080fdd7fe248455 validate cover format on document create --- diff --git a/apps/catalogue/forms.py b/apps/catalogue/forms.py index 9301d9b7..e6a6412f 100644 --- a/apps/catalogue/forms.py +++ b/apps/catalogue/forms.py @@ -51,6 +51,12 @@ class DocumentCreateForm(forms.Form): # # return self.cleaned_data + def clean_cover(self): + cover = self.cleaned_data['cover'] + if cover.name.rsplit('.', 1)[-1].lower() not in ('jpg', 'jpeg', 'png', 'gif', 'tif', 'tiff'): + raise forms.ValidationError('The cover should be an image file (jpg/png/gif)') + return file + class DocumentsUploadForm(forms.Form): """