gremmie@1: """ gremmie@1: Forms for the member map application. gremmie@1: """ gremmie@1: from django import forms bgneal@6: bgneal@1024: from core.html import ImageCheckError bgneal@1024: from core.html import image_check bgneal@1024: from core.markup import site_markup gremmie@1: from membermap.models import MapEntry gremmie@1: gremmie@1: gremmie@1: class MapEntryForm(forms.ModelForm): bgneal@1077: location = forms.CharField(required=True, label='Your Location') bgneal@1077: message = forms.CharField(required=False, label='Your Message', bgneal@133: widget=forms.Textarea(attrs={'class': 'markItUp smileyTarget'})) gremmie@1: bgneal@1024: def clean_message(self): bgneal@1024: message = self.cleaned_data['message'] bgneal@1024: self.html = None bgneal@1024: bgneal@1024: if message: bgneal@1024: self.html = site_markup(message) bgneal@1024: try: bgneal@1024: image_check(self.html) bgneal@1024: except ImageCheckError as ex: bgneal@1024: raise forms.ValidationError(str(ex)) bgneal@1024: bgneal@1024: return message bgneal@1024: gremmie@1: class Meta: gremmie@1: model = MapEntry gremmie@1: fields = ('location', 'message')