annotate membermap/forms.py @ 1070:6ac56115e0a8

Convert contact form & views to V3.
author Brian Neal <bgneal@gmail.com>
date Sat, 09 Apr 2016 17:15:32 -0500
parents 6164cc091649
children 26f2b83e7468
rev   line source
gremmie@1 1 """
gremmie@1 2 Forms for the member map application.
gremmie@1 3 """
gremmie@1 4 from django import forms
bgneal@6 5
bgneal@1024 6 from core.html import ImageCheckError
bgneal@1024 7 from core.html import image_check
bgneal@1024 8 from core.markup import site_markup
gremmie@1 9 from membermap.models import MapEntry
gremmie@1 10
gremmie@1 11
gremmie@1 12 class MapEntryForm(forms.ModelForm):
bgneal@312 13 location = forms.CharField(required=True,
bgneal@133 14 widget=forms.TextInput(attrs={'size': 64, 'maxlength': 255}))
bgneal@312 15 message = forms.CharField(required=False,
bgneal@133 16 widget=forms.Textarea(attrs={'class': 'markItUp smileyTarget'}))
gremmie@1 17
bgneal@1024 18 def clean_message(self):
bgneal@1024 19 message = self.cleaned_data['message']
bgneal@1024 20 self.html = None
bgneal@1024 21
bgneal@1024 22 if message:
bgneal@1024 23 self.html = site_markup(message)
bgneal@1024 24 try:
bgneal@1024 25 image_check(self.html)
bgneal@1024 26 except ImageCheckError as ex:
bgneal@1024 27 raise forms.ValidationError(str(ex))
bgneal@1024 28
bgneal@1024 29 return message
bgneal@1024 30
gremmie@1 31 class Meta:
gremmie@1 32 model = MapEntry
gremmie@1 33 fields = ('location', 'message')