gremmie@1: """ gremmie@1: Forms for the news application. gremmie@1: """ gremmie@1: gremmie@1: from django import forms gremmie@1: from news.models import PendingStory gremmie@1: from news.models import Category gremmie@1: gremmie@1: gremmie@1: class AddNewsForm(forms.ModelForm): gremmie@1: """Form for a user to submit a news story to the admins for review.""" gremmie@1: title = forms.CharField(widget=forms.TextInput(attrs={'size': 52})) gremmie@1: short_text = forms.CharField(widget=forms.Textarea(attrs={'rows': 20, 'cols': 80})) gremmie@1: long_text = forms.CharField(required=False, widget=forms.Textarea(attrs={'rows': 20, 'cols': 80})) gremmie@1: gremmie@1: class Meta: gremmie@1: model = PendingStory gremmie@1: exclude = ('submitter', 'date_submitted', 'allow_comments', 'approved', 'tags') gremmie@1: gremmie@1: class Media: gremmie@1: js = ('js/tiny_mce/tiny_mce.js', 'js/tiny_mce_init_std.js') gremmie@1: gremmie@1: gremmie@1: class SearchNewsForm(forms.Form): gremmie@1: """Form for a user to search news stories.""" gremmie@1: text = forms.CharField(max_length=30) gremmie@1: category = forms.ModelChoiceField(label='', gremmie@1: required=False, gremmie@1: empty_label='(All Categories)', gremmie@1: queryset=Category.objects.all()) gremmie@1: gremmie@1: def get_query(self): gremmie@1: return self.cleaned_data['text'] gremmie@1: gremmie@1: def get_category(self): gremmie@1: cat = self.cleaned_data['category'] gremmie@1: if cat: gremmie@1: return cat gremmie@1: return None gremmie@1: gremmie@1: gremmie@1: class SendStoryForm(forms.Form): gremmie@1: """Form for sending a news story via email to a friend.""" gremmie@1: friend_name = forms.CharField(label="Friend's Name", max_length=64) gremmie@1: friend_email = forms.EmailField(label="Friend's Email") gremmie@1: gremmie@1: def email(self): gremmie@1: return self.cleaned_data['friend_email'] gremmie@1: gremmie@1: def name(self): gremmie@1: return self.cleaned_data['friend_name'] gremmie@1: gremmie@1: