comparison 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
comparison
equal deleted inserted replaced
1020:a052798c146c 1021:68c3343f3318
3 """ 3 """
4 import datetime 4 import datetime
5 import pytz 5 import pytz
6 from django import forms 6 from django import forms
7 7
8 from core.html import ImageCheckError
9 from core.html import image_check
10 from core.markup import site_markup
8 from gcalendar.models import Event 11 from gcalendar.models import Event
9 12
10 13
11 TIME_CHOICES = ( 14 TIME_CHOICES = (
12 ('00:00', '12:00 am (00:00)'), 15 ('00:00', '12:00 am (00:00)'),
66 start_time = forms.TimeField(required=False, widget=forms.Select(choices=TIME_CHOICES)) 69 start_time = forms.TimeField(required=False, widget=forms.Select(choices=TIME_CHOICES))
67 end_date = forms.DateField(widget=forms.TextInput(attrs={'size': 10})) 70 end_date = forms.DateField(widget=forms.TextInput(attrs={'size': 10}))
68 end_time = forms.TimeField(required=False, widget=forms.Select(choices=TIME_CHOICES)) 71 end_time = forms.TimeField(required=False, widget=forms.Select(choices=TIME_CHOICES))
69 time_zone = forms.CharField(required=False, widget=forms.HiddenInput()) 72 time_zone = forms.CharField(required=False, widget=forms.HiddenInput())
70 where = forms.CharField(required=False, widget=forms.TextInput(attrs={'size': 60})) 73 where = forms.CharField(required=False, widget=forms.TextInput(attrs={'size': 60}))
71 description = forms.CharField(required=False, 74 description = forms.CharField(
72 widget=forms.Textarea(attrs={'class': 'markItUp smileyTarget'})) 75 required=False,
76 widget=forms.Textarea(attrs={
77 'class': 'markItUp smileyTarget',
78 'id': 'id_body', # needed for image related js
79 }))
73 80
74 DATE_FORMAT = '%m/%d/%Y' # must match the jQuery UI datepicker config 81 DATE_FORMAT = '%m/%d/%Y' # must match the jQuery UI datepicker config
75 TIME_FORMAT = '%H:%M' 82 TIME_FORMAT = '%H:%M'
76 DEFAULT_START_TIME = '19:00' 83 DEFAULT_START_TIME = '19:00'
77 DEFAULT_END_TIME = '20:00' 84 DEFAULT_END_TIME = '20:00'
114 121
115 # We don't want the user to create a forum thread on an existing event 122 # We don't want the user to create a forum thread on an existing event
116 if instance is not None: 123 if instance is not None:
117 del self.fields['create_forum_thread'] 124 del self.fields['create_forum_thread']
118 125
126 def clean_description(self):
127 description = self.cleaned_data['description']
128 self.html = None
129 if description:
130 self.html = site_markup(description, relative_urls=False)
131 try:
132 image_check(self.html)
133 except ImageCheckError as ex:
134 raise forms.ValidationError(str(ex))
135 return description
136
119 def clean(self): 137 def clean(self):
120 start_date = self.cleaned_data.get('start_date') 138 start_date = self.cleaned_data.get('start_date')
121 start_time = self.cleaned_data.get('start_time') 139 start_time = self.cleaned_data.get('start_time')
122 all_day = self.cleaned_data.get('all_day') 140 all_day = self.cleaned_data.get('all_day')
123 end_date = self.cleaned_data.get('end_date') 141 end_date = self.cleaned_data.get('end_date')