From b7cdf38bdc5fbff4a13a7cf1aa4f3ff1b7232368 Mon Sep 17 00:00:00 2001 From: Jan Szejko Date: Wed, 1 Feb 2017 17:06:45 +0100 Subject: [PATCH 1/1] validate cover format on document create --- apps/catalogue/forms.py | 6 ++++++ 1 file changed, 6 insertions(+) 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): """ -- 2.20.1