validate cover format on document create
authorJan Szejko <janek37@gmail.com>
Wed, 1 Feb 2017 16:06:45 +0000 (17:06 +0100)
committerJan Szejko <janek37@gmail.com>
Wed, 1 Feb 2017 16:06:45 +0000 (17:06 +0100)
apps/catalogue/forms.py

index 9301d9b..e6a6412 100644 (file)
@@ -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):
     """