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