annotate news/forms.py @ 1010:9afe0610aae5

Move SSL related settings to production module.
author Brian Neal <bgneal@gmail.com>
date Fri, 27 Nov 2015 15:44:06 -0600
parents fa52bfb28217
children 21c592cac71c
rev   line source
gremmie@1 1 """
gremmie@1 2 Forms for the news application.
bgneal@493 3
gremmie@1 4 """
gremmie@1 5 from django import forms
bgneal@7 6 from django.conf import settings
bgneal@7 7
bgneal@997 8 from core.html import ImageCheckError
bgneal@997 9 from core.html import image_check
bgneal@997 10 from core.markup import site_markup
gremmie@1 11 from news.models import PendingStory
gremmie@1 12
gremmie@1 13
gremmie@1 14 class AddNewsForm(forms.ModelForm):
bgneal@997 15 """Form for a user to submit a news story to the admins for review."""
bgneal@997 16 title = forms.CharField(widget=forms.TextInput(attrs={'size': 52}))
bgneal@997 17 short_markup = forms.CharField(
bgneal@997 18 label="Article text",
bgneal@997 19 widget=forms.Textarea(attrs={
bgneal@1003 20 'id': 'id_body', # needed for image related js
bgneal@997 21 'rows': 60,
bgneal@997 22 'cols': 80,
bgneal@997 23 'class': 'markItUp smileyTarget',
bgneal@997 24 'style': 'height:500px',
bgneal@997 25 }))
gremmie@1 26
bgneal@997 27 class Meta:
bgneal@997 28 model = PendingStory
bgneal@997 29 fields = ['title', 'category', 'short_markup']
gremmie@1 30
bgneal@997 31 class Media:
bgneal@997 32 css = {
bgneal@997 33 'all': (settings.GPP_THIRD_PARTY_CSS['markitup'] +
bgneal@997 34 settings.GPP_THIRD_PARTY_CSS['jquery-ui'])
bgneal@997 35 }
bgneal@997 36 js = (
bgneal@997 37 settings.GPP_THIRD_PARTY_JS['markitup'] +
bgneal@997 38 settings.GPP_THIRD_PARTY_JS['jquery-ui'] +
bgneal@997 39 ['js/jquery.form.min.js']
bgneal@997 40 )
bgneal@997 41
bgneal@997 42 def clean_short_markup(self):
bgneal@997 43 md = self.cleaned_data['short_markup']
bgneal@997 44 self.html = None
bgneal@997 45 if not md:
bgneal@997 46 raise forms.ValidationError("Please enter some article text")
bgneal@997 47
bgneal@997 48 if md:
bgneal@997 49 self.html = site_markup(md)
bgneal@997 50 try:
bgneal@997 51 image_check(self.html)
bgneal@997 52 except ImageCheckError as ex:
bgneal@997 53 raise forms.ValidationError(str(ex))
bgneal@997 54
bgneal@997 55 return md
bgneal@997 56
bgneal@997 57 def save(self, user):
bgneal@997 58 pending_story = super(AddNewsForm, self).save(commit=False)
bgneal@997 59 pending_story.submitter = user
bgneal@997 60 pending_story.save(short_text=self.html)
bgneal@997 61 return pending_story
gremmie@1 62
gremmie@1 63
gremmie@1 64 class SendStoryForm(forms.Form):
bgneal@997 65 """Form for sending a news story via email to a friend."""
bgneal@997 66 friend_name = forms.CharField(label="Friend's Name", max_length=64)
bgneal@997 67 friend_email = forms.EmailField(label="Friend's Email")
gremmie@1 68
bgneal@997 69 def email(self):
bgneal@997 70 return self.cleaned_data['friend_email']
bgneal@312 71
bgneal@997 72 def name(self):
bgneal@997 73 return self.cleaned_data['friend_name']
gremmie@1 74