Mercurial > public > sg101
diff downloads/forms.py @ 1023:a5ebc74dc3f3
Perform image_check on downloads.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Thu, 10 Dec 2015 20:57:50 -0600 |
parents | 21c592cac71c |
children |
line wrap: on
line diff
--- a/downloads/forms.py Wed Dec 09 21:16:04 2015 -0600 +++ b/downloads/forms.py Thu Dec 10 20:57:50 2015 -0600 @@ -5,6 +5,9 @@ from django import forms +from core.html import ImageCheckError +from core.html import image_check +from core.markup import site_markup from downloads.models import PendingDownload from downloads.models import AllowedExtension @@ -16,6 +19,20 @@ description = forms.CharField(required=False, widget=forms.Textarea(attrs={'class': 'markItUp smileyTarget'})) + def clean_description(self): + description = self.cleaned_data['description'].strip() + self.html = None + if not description: + raise forms.ValidationError("Please enter a description") + + self.html = site_markup(description) + try: + image_check(self.html) + except ImageCheckError as ex: + raise forms.ValidationError(str(ex)) + + return description + def clean_file(self): file = self.cleaned_data['file'] ext = os.path.splitext(file.name)[1]