diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gpp/news/forms.py	Mon Apr 06 02:43:12 2009 +0000
@@ -0,0 +1,53 @@
+"""
+Forms for the news application.
+"""
+
+from django import forms
+from news.models import PendingStory
+from news.models import Category
+
+
+class AddNewsForm(forms.ModelForm):
+   """Form for a user to submit a news story to the admins for review."""
+   title = forms.CharField(widget=forms.TextInput(attrs={'size': 52}))
+   short_text = forms.CharField(widget=forms.Textarea(attrs={'rows': 20, 'cols': 80}))
+   long_text = forms.CharField(required=False, widget=forms.Textarea(attrs={'rows': 20, 'cols': 80}))
+
+   class Meta:
+      model = PendingStory
+      exclude = ('submitter', 'date_submitted', 'allow_comments', 'approved', 'tags')
+
+   class Media:
+      js = ('js/tiny_mce/tiny_mce.js', 'js/tiny_mce_init_std.js')
+
+
+class SearchNewsForm(forms.Form):
+   """Form for a user to search news stories."""
+   text = forms.CharField(max_length=30)
+   category = forms.ModelChoiceField(label='', 
+         required=False,
+         empty_label='(All Categories)',
+         queryset=Category.objects.all())
+
+   def get_query(self):
+      return self.cleaned_data['text']
+
+   def get_category(self):
+      cat = self.cleaned_data['category']
+      if cat:
+         return cat
+      return None
+
+
+class SendStoryForm(forms.Form):
+   """Form for sending a news story via email to a friend."""
+   friend_name = forms.CharField(label="Friend's Name", max_length=64)
+   friend_email = forms.EmailField(label="Friend's Email")
+
+   def email(self):
+      return self.cleaned_data['friend_email']
+      
+   def name(self):
+      return self.cleaned_data['friend_name']
+
+