Mercurial > public > sg101
comparison membermap/forms.py @ 1024:6164cc091649
Perform image_check on membermap messages.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Thu, 10 Dec 2015 21:11:10 -0600 |
parents | 21c592cac71c |
children | 26f2b83e7468 |
comparison
equal
deleted
inserted
replaced
1023:a5ebc74dc3f3 | 1024:6164cc091649 |
---|---|
1 """ | 1 """ |
2 Forms for the member map application. | 2 Forms for the member map application. |
3 """ | 3 """ |
4 from django import forms | 4 from django import forms |
5 | 5 |
6 from core.html import ImageCheckError | |
7 from core.html import image_check | |
8 from core.markup import site_markup | |
6 from membermap.models import MapEntry | 9 from membermap.models import MapEntry |
7 | 10 |
8 | 11 |
9 class MapEntryForm(forms.ModelForm): | 12 class MapEntryForm(forms.ModelForm): |
10 location = forms.CharField(required=True, | 13 location = forms.CharField(required=True, |
11 widget=forms.TextInput(attrs={'size': 64, 'maxlength': 255})) | 14 widget=forms.TextInput(attrs={'size': 64, 'maxlength': 255})) |
12 message = forms.CharField(required=False, | 15 message = forms.CharField(required=False, |
13 widget=forms.Textarea(attrs={'class': 'markItUp smileyTarget'})) | 16 widget=forms.Textarea(attrs={'class': 'markItUp smileyTarget'})) |
14 | 17 |
18 def clean_message(self): | |
19 message = self.cleaned_data['message'] | |
20 self.html = None | |
21 | |
22 if message: | |
23 self.html = site_markup(message) | |
24 try: | |
25 image_check(self.html) | |
26 except ImageCheckError as ex: | |
27 raise forms.ValidationError(str(ex)) | |
28 | |
29 return message | |
30 | |
15 class Meta: | 31 class Meta: |
16 model = MapEntry | 32 model = MapEntry |
17 fields = ('location', 'message') | 33 fields = ('location', 'message') |