bgneal@83: """ bgneal@83: Forms for the forums application. bgneal@83: """ bgneal@83: from django import forms bgneal@83: bgneal@83: from forums.models import Topic bgneal@83: from forums.models import Post bgneal@83: bgneal@83: bgneal@86: class PostForm(forms.Form): bgneal@86: """Form for creating a new post.""" bgneal@86: body = forms.CharField(label='', widget=forms.Textarea) bgneal@83: bgneal@86: def save(self, topic, user, ip=None): bgneal@86: """ bgneal@86: Creates a new post from the form data and supplied arguments. bgneal@86: """ bgneal@86: post = Post(topic=topic, user=user, body=self.cleaned_data['body'], bgneal@86: user_ip=user_ip) bgneal@86: post.save() bgneal@83: bgneal@83: bgneal@83: class NewTopicForm(forms.Form): bgneal@83: """Form for creating a new topic and 1st post to that topic.""" bgneal@83: name = forms.CharField(label='Subject', max_length=255) bgneal@83: body = forms.CharField(label='', widget=forms.Textarea) bgneal@83: bgneal@83: def save(self, forum, user, ip=None): bgneal@83: """ bgneal@83: Creates the new Topic and first Post from the form data and supplied bgneal@86: arguments. bgneal@83: """ bgneal@83: topic = Topic(forum=forum, bgneal@83: name=self.cleaned_data['name'], bgneal@83: user=user) bgneal@83: topic.save() bgneal@83: bgneal@83: post = Post(topic=topic, bgneal@83: user=user, bgneal@83: body=self.cleaned_data['body'], bgneal@83: user_ip=ip) bgneal@83: post.save() bgneal@83: bgneal@83: return topic