comparison gpp/forums/forms.py @ 83:5b4c812b448e

Forums: Added the ability to add a new topic. This is very much a work in progress.
author Brian Neal <bgneal@gmail.com>
date Sat, 29 Aug 2009 20:54:16 +0000
parents
children f81226b5e87b
comparison
equal deleted inserted replaced
82:bc3978f023c2 83:5b4c812b448e
1 """
2 Forms for the forums application.
3 """
4 from django import forms
5
6 from forums.models import Topic
7 from forums.models import Post
8
9
10 class TopicForm(forms.ModelForm):
11 """Form for creating a new topic."""
12
13 class Meta:
14 model = Topic
15 fields = ('name', )
16
17
18 class PostForm(forms.ModelForm):
19 """Form for creating a new post."""
20
21 class Meta:
22 model = Post
23 fields = ('body', )
24
25
26 class NewTopicForm(forms.Form):
27 """Form for creating a new topic and 1st post to that topic."""
28 name = forms.CharField(label='Subject', max_length=255)
29 body = forms.CharField(label='', widget=forms.Textarea)
30
31 def save(self, forum, user, ip=None):
32 """
33 Creates the new Topic and first Post from the form data and supplied
34 forum and user objects.
35 """
36 topic = Topic(forum=forum,
37 name=self.cleaned_data['name'],
38 user=user)
39 topic.save()
40
41 post = Post(topic=topic,
42 user=user,
43 body=self.cleaned_data['body'],
44 user_ip=ip)
45 post.save()
46
47 return topic