Mercurial > public > sg101
comparison 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 |
comparison
equal
deleted
inserted
replaced
85:531fcc342a03 | 86:f81226b5e87b |
---|---|
5 | 5 |
6 from forums.models import Topic | 6 from forums.models import Topic |
7 from forums.models import Post | 7 from forums.models import Post |
8 | 8 |
9 | 9 |
10 class TopicForm(forms.ModelForm): | 10 class PostForm(forms.Form): |
11 """Form for creating a new topic.""" | 11 """Form for creating a new post.""" |
12 | 12 body = forms.CharField(label='', widget=forms.Textarea) |
13 class Meta: | |
14 model = Topic | |
15 fields = ('name', ) | |
16 | 13 |
17 | 14 def save(self, topic, user, ip=None): |
18 class PostForm(forms.ModelForm): | 15 """ |
19 """Form for creating a new post.""" | 16 Creates a new post from the form data and supplied arguments. |
20 | 17 """ |
21 class Meta: | 18 post = Post(topic=topic, user=user, body=self.cleaned_data['body'], |
22 model = Post | 19 user_ip=user_ip) |
23 fields = ('body', ) | 20 post.save() |
24 | 21 |
25 | 22 |
26 class NewTopicForm(forms.Form): | 23 class NewTopicForm(forms.Form): |
27 """Form for creating a new topic and 1st post to that topic.""" | 24 """Form for creating a new topic and 1st post to that topic.""" |
28 name = forms.CharField(label='Subject', max_length=255) | 25 name = forms.CharField(label='Subject', max_length=255) |
29 body = forms.CharField(label='', widget=forms.Textarea) | 26 body = forms.CharField(label='', widget=forms.Textarea) |
30 | 27 |
31 def save(self, forum, user, ip=None): | 28 def save(self, forum, user, ip=None): |
32 """ | 29 """ |
33 Creates the new Topic and first Post from the form data and supplied | 30 Creates the new Topic and first Post from the form data and supplied |
34 forum and user objects. | 31 arguments. |
35 """ | 32 """ |
36 topic = Topic(forum=forum, | 33 topic = Topic(forum=forum, |
37 name=self.cleaned_data['name'], | 34 name=self.cleaned_data['name'], |
38 user=user) | 35 user=user) |
39 topic.save() | 36 topic.save() |