Mercurial > public > sg101
comparison gpp/forums/forms.py @ 89:021492db4aad
Forums: Got the reply function working.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Sat, 12 Sep 2009 21:29:31 +0000 |
parents | f81226b5e87b |
children | 23035afdeae8 |
comparison
equal
deleted
inserted
replaced
88:3abf0b045749 | 89:021492db4aad |
---|---|
8 | 8 |
9 | 9 |
10 class PostForm(forms.Form): | 10 class PostForm(forms.Form): |
11 """Form for creating a new post.""" | 11 """Form for creating a new post.""" |
12 body = forms.CharField(label='', widget=forms.Textarea) | 12 body = forms.CharField(label='', widget=forms.Textarea) |
13 topic_id = forms.IntegerField(widget=forms.HiddenInput) | |
14 topic = None | |
13 | 15 |
14 def save(self, topic, user, ip=None): | 16 class Media: |
17 js = ('js/forums.js', ) | |
18 | |
19 def clean_topic_id(self): | |
20 id = self.cleaned_data['topic_id'] | |
21 print '*********', id | |
22 try: | |
23 self.topic = Topic.objects.get(pk=id) | |
24 print '******** Got a topic' | |
25 except Topic.DoesNotExist: | |
26 raise forms.ValidationError('invalid topic') | |
27 return id | |
28 | |
29 def save(self, user, ip=None): | |
15 """ | 30 """ |
16 Creates a new post from the form data and supplied arguments. | 31 Creates a new post from the form data and supplied arguments. |
17 """ | 32 """ |
18 post = Post(topic=topic, user=user, body=self.cleaned_data['body'], | 33 post = Post(topic=self.topic, user=user, body=self.cleaned_data['body'], |
19 user_ip=user_ip) | 34 user_ip=ip) |
20 post.save() | 35 post.save() |
36 return post | |
21 | 37 |
22 | 38 |
23 class NewTopicForm(forms.Form): | 39 class NewTopicForm(forms.Form): |
24 """Form for creating a new topic and 1st post to that topic.""" | 40 """Form for creating a new topic and 1st post to that topic.""" |
25 name = forms.CharField(label='Subject', max_length=255) | 41 name = forms.CharField(label='Subject', max_length=255) |