annotate gpp/news/forms.py @ 190:0e4961833cdf

Added some select_related's to downloads.
author Brian Neal <bgneal@gmail.com>
date Thu, 01 Apr 2010 01:57:01 +0000
parents ca66189c7c44
children 6dbb8faef085
rev   line source
gremmie@1 1 """
gremmie@1 2 Forms for the news application.
gremmie@1 3 """
gremmie@1 4
gremmie@1 5 from django import forms
bgneal@7 6 from django.conf import settings
bgneal@7 7
gremmie@1 8 from news.models import PendingStory
gremmie@1 9 from news.models import Category
gremmie@1 10
gremmie@1 11
gremmie@1 12 class AddNewsForm(forms.ModelForm):
gremmie@1 13 """Form for a user to submit a news story to the admins for review."""
gremmie@1 14 title = forms.CharField(widget=forms.TextInput(attrs={'size': 52}))
gremmie@1 15 short_text = forms.CharField(widget=forms.Textarea(attrs={'rows': 20, 'cols': 80}))
gremmie@1 16 long_text = forms.CharField(required=False, widget=forms.Textarea(attrs={'rows': 20, 'cols': 80}))
gremmie@1 17
gremmie@1 18 class Meta:
gremmie@1 19 model = PendingStory
gremmie@1 20 exclude = ('submitter', 'date_submitted', 'allow_comments', 'approved', 'tags')
gremmie@1 21
gremmie@1 22 class Media:
bgneal@7 23 js = settings.GPP_THIRD_PARTY_JS['tiny_mce']
gremmie@1 24
gremmie@1 25
gremmie@1 26 class SearchNewsForm(forms.Form):
gremmie@1 27 """Form for a user to search news stories."""
gremmie@1 28 text = forms.CharField(max_length=30)
gremmie@1 29 category = forms.ModelChoiceField(label='',
gremmie@1 30 required=False,
gremmie@1 31 empty_label='(All Categories)',
gremmie@1 32 queryset=Category.objects.all())
gremmie@1 33
gremmie@1 34 def get_query(self):
gremmie@1 35 return self.cleaned_data['text']
gremmie@1 36
gremmie@1 37 def get_category(self):
gremmie@1 38 cat = self.cleaned_data['category']
gremmie@1 39 if cat:
gremmie@1 40 return cat
gremmie@1 41 return None
gremmie@1 42
gremmie@1 43
gremmie@1 44 class SendStoryForm(forms.Form):
gremmie@1 45 """Form for sending a news story via email to a friend."""
gremmie@1 46 friend_name = forms.CharField(label="Friend's Name", max_length=64)
gremmie@1 47 friend_email = forms.EmailField(label="Friend's Email")
gremmie@1 48
gremmie@1 49 def email(self):
gremmie@1 50 return self.cleaned_data['friend_email']
gremmie@1 51
gremmie@1 52 def name(self):
gremmie@1 53 return self.cleaned_data['friend_name']
gremmie@1 54