annotate gpp/forums/forms.py @ 86:f81226b5e87b

Forums: Some display work for the posts within a topic. Sketched out a post reply form.
author Brian Neal <bgneal@gmail.com>
date Sat, 05 Sep 2009 20:47:08 +0000
parents 5b4c812b448e
children 021492db4aad
rev   line source
bgneal@83 1 """
bgneal@83 2 Forms for the forums application.
bgneal@83 3 """
bgneal@83 4 from django import forms
bgneal@83 5
bgneal@83 6 from forums.models import Topic
bgneal@83 7 from forums.models import Post
bgneal@83 8
bgneal@83 9
bgneal@86 10 class PostForm(forms.Form):
bgneal@86 11 """Form for creating a new post."""
bgneal@86 12 body = forms.CharField(label='', widget=forms.Textarea)
bgneal@83 13
bgneal@86 14 def save(self, topic, user, ip=None):
bgneal@86 15 """
bgneal@86 16 Creates a new post from the form data and supplied arguments.
bgneal@86 17 """
bgneal@86 18 post = Post(topic=topic, user=user, body=self.cleaned_data['body'],
bgneal@86 19 user_ip=user_ip)
bgneal@86 20 post.save()
bgneal@83 21
bgneal@83 22
bgneal@83 23 class NewTopicForm(forms.Form):
bgneal@83 24 """Form for creating a new topic and 1st post to that topic."""
bgneal@83 25 name = forms.CharField(label='Subject', max_length=255)
bgneal@83 26 body = forms.CharField(label='', widget=forms.Textarea)
bgneal@83 27
bgneal@83 28 def save(self, forum, user, ip=None):
bgneal@83 29 """
bgneal@83 30 Creates the new Topic and first Post from the form data and supplied
bgneal@86 31 arguments.
bgneal@83 32 """
bgneal@83 33 topic = Topic(forum=forum,
bgneal@83 34 name=self.cleaned_data['name'],
bgneal@83 35 user=user)
bgneal@83 36 topic.save()
bgneal@83 37
bgneal@83 38 post = Post(topic=topic,
bgneal@83 39 user=user,
bgneal@83 40 body=self.cleaned_data['body'],
bgneal@83 41 user_ip=ip)
bgneal@83 42 post.save()
bgneal@83 43
bgneal@83 44 return topic