Mercurial > public > sg101
annotate membermap/forms.py @ 1107:977e76f7f736
POTD converted to V3 design.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Wed, 06 Jul 2016 21:41:16 -0500 |
parents | 26f2b83e7468 |
children |
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@1077 | 13 location = forms.CharField(required=True, label='Your Location') |
bgneal@1077 | 14 message = forms.CharField(required=False, label='Your Message', |
bgneal@133 | 15 widget=forms.Textarea(attrs={'class': 'markItUp smileyTarget'})) |
gremmie@1 | 16 |
bgneal@1024 | 17 def clean_message(self): |
bgneal@1024 | 18 message = self.cleaned_data['message'] |
bgneal@1024 | 19 self.html = None |
bgneal@1024 | 20 |
bgneal@1024 | 21 if message: |
bgneal@1024 | 22 self.html = site_markup(message) |
bgneal@1024 | 23 try: |
bgneal@1024 | 24 image_check(self.html) |
bgneal@1024 | 25 except ImageCheckError as ex: |
bgneal@1024 | 26 raise forms.ValidationError(str(ex)) |
bgneal@1024 | 27 |
bgneal@1024 | 28 return message |
bgneal@1024 | 29 |
gremmie@1 | 30 class Meta: |
gremmie@1 | 31 model = MapEntry |
gremmie@1 | 32 fields = ('location', 'message') |