Mercurial > public > sg101
diff gcalendar/forms.py @ 1021:68c3343f3318
Perform image_check on gcalendar description.
Also add image hotlink/upload forms to gcalendar add event page.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Tue, 08 Dec 2015 21:39:19 -0600 |
parents | 21c592cac71c |
children | f0ac48aa8c64 |
line wrap: on
line diff
--- a/gcalendar/forms.py Tue Dec 08 17:32:31 2015 -0600 +++ b/gcalendar/forms.py Tue Dec 08 21:39:19 2015 -0600 @@ -5,6 +5,9 @@ import pytz from django import forms +from core.html import ImageCheckError +from core.html import image_check +from core.markup import site_markup from gcalendar.models import Event @@ -68,8 +71,12 @@ end_time = forms.TimeField(required=False, widget=forms.Select(choices=TIME_CHOICES)) time_zone = forms.CharField(required=False, widget=forms.HiddenInput()) where = forms.CharField(required=False, widget=forms.TextInput(attrs={'size': 60})) - description = forms.CharField(required=False, - widget=forms.Textarea(attrs={'class': 'markItUp smileyTarget'})) + description = forms.CharField( + required=False, + widget=forms.Textarea(attrs={ + 'class': 'markItUp smileyTarget', + 'id': 'id_body', # needed for image related js + })) DATE_FORMAT = '%m/%d/%Y' # must match the jQuery UI datepicker config TIME_FORMAT = '%H:%M' @@ -116,6 +123,17 @@ if instance is not None: del self.fields['create_forum_thread'] + def clean_description(self): + description = self.cleaned_data['description'] + self.html = None + if description: + self.html = site_markup(description, relative_urls=False) + try: + image_check(self.html) + except ImageCheckError as ex: + raise forms.ValidationError(str(ex)) + return description + def clean(self): start_date = self.cleaned_data.get('start_date') start_time = self.cleaned_data.get('start_time')