From 9dba8c0abd9b926e92f24440a8fe239bf233dc99 Mon Sep 17 00:00:00 2001 From: adi Date: Thu, 25 Aug 2016 21:06:00 +0200 Subject: [PATCH] Corrupted image upload exception --- README.md | 4 ++++ markdownx/forms.py | 17 +++++++++-------- setup.py | 2 +- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 76a3391..5414d4d 100755 --- a/README.md +++ b/README.md @@ -327,6 +327,10 @@ $('.markdownx').on('markdownx.update', function(e, response) { # Changelog +###### v1.6.3 + +* Corrupted image upload exception + ###### v1.6.2 * Runtest template fix diff --git a/markdownx/forms.py b/markdownx/forms.py index 78d9db3..778b1a0 100755 --- a/markdownx/forms.py +++ b/markdownx/forms.py @@ -42,12 +42,13 @@ class ImageForm(forms.Form): return filename def clean(self): - upload = self.cleaned_data['image'] - content_type = upload.content_type - if content_type in MARKDOWNX_UPLOAD_CONTENT_TYPES: - if upload._size > MARKDOWNX_UPLOAD_MAX_SIZE: - raise forms.ValidationError(_('Please keep filesize under %(max)s. Current filesize %(current)s') % {'max':filters.filesizeformat(MARKDOWNX_UPLOAD_MAX_SIZE), 'current':filters.filesizeformat(upload._size)}) - else: - raise forms.ValidationError(_('File type is not supported')) + upload = self.cleaned_data.get('image') + if upload: + content_type = upload.content_type + if content_type in MARKDOWNX_UPLOAD_CONTENT_TYPES: + if upload._size > MARKDOWNX_UPLOAD_MAX_SIZE: + raise forms.ValidationError(_('Please keep filesize under %(max)s. Current filesize %(current)s') % {'max':filters.filesizeformat(MARKDOWNX_UPLOAD_MAX_SIZE), 'current':filters.filesizeformat(upload._size)}) + else: + raise forms.ValidationError(_('File type is not supported')) - return upload + return upload diff --git a/setup.py b/setup.py index c9791a8..48e4f21 100755 --- a/setup.py +++ b/setup.py @@ -10,7 +10,7 @@ def get_requirements(): setup( name='django-markdownx', - version='1.6.2', + version='1.6.3', packages=find_packages(), include_package_data=True, description='django-markdownx is a Markdown editor built for Django.',