annotate gpp/news/forms.py @ 1:dbd703f7d63a

Initial import of sg101 stuff from private repository.
author gremmie
date Mon, 06 Apr 2009 02:43:12 +0000
parents
children ca66189c7c44
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
gremmie@1 6 from news.models import PendingStory
gremmie@1 7 from news.models import Category
gremmie@1 8
gremmie@1 9
gremmie@1 10 class AddNewsForm(forms.ModelForm):
gremmie@1 11 """Form for a user to submit a news story to the admins for review."""
gremmie@1 12 title = forms.CharField(widget=forms.TextInput(attrs={'size': 52}))
gremmie@1 13 short_text = forms.CharField(widget=forms.Textarea(attrs={'rows': 20, 'cols': 80}))
gremmie@1 14 long_text = forms.CharField(required=False, widget=forms.Textarea(attrs={'rows': 20, 'cols': 80}))
gremmie@1 15
gremmie@1 16 class Meta:
gremmie@1 17 model = PendingStory
gremmie@1 18 exclude = ('submitter', 'date_submitted', 'allow_comments', 'approved', 'tags')
gremmie@1 19
gremmie@1 20 class Media:
gremmie@1 21 js = ('js/tiny_mce/tiny_mce.js', 'js/tiny_mce_init_std.js')
gremmie@1 22
gremmie@1 23
gremmie@1 24 class SearchNewsForm(forms.Form):
gremmie@1 25 """Form for a user to search news stories."""
gremmie@1 26 text = forms.CharField(max_length=30)
gremmie@1 27 category = forms.ModelChoiceField(label='',
gremmie@1 28 required=False,
gremmie@1 29 empty_label='(All Categories)',
gremmie@1 30 queryset=Category.objects.all())
gremmie@1 31
gremmie@1 32 def get_query(self):
gremmie@1 33 return self.cleaned_data['text']
gremmie@1 34
gremmie@1 35 def get_category(self):
gremmie@1 36 cat = self.cleaned_data['category']
gremmie@1 37 if cat:
gremmie@1 38 return cat
gremmie@1 39 return None
gremmie@1 40
gremmie@1 41
gremmie@1 42 class SendStoryForm(forms.Form):
gremmie@1 43 """Form for sending a news story via email to a friend."""
gremmie@1 44 friend_name = forms.CharField(label="Friend's Name", max_length=64)
gremmie@1 45 friend_email = forms.EmailField(label="Friend's Email")
gremmie@1 46
gremmie@1 47 def email(self):
gremmie@1 48 return self.cleaned_data['friend_email']
gremmie@1 49
gremmie@1 50 def name(self):
gremmie@1 51 return self.cleaned_data['friend_name']
gremmie@1 52
gremmie@1 53