Mercurial > public > sg101
diff 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 |
line wrap: on
line diff
--- a/gpp/forums/forms.py Sat Sep 12 18:51:55 2009 +0000 +++ b/gpp/forums/forms.py Sat Sep 12 21:29:31 2009 +0000 @@ -10,14 +10,30 @@ class PostForm(forms.Form): """Form for creating a new post.""" body = forms.CharField(label='', widget=forms.Textarea) + topic_id = forms.IntegerField(widget=forms.HiddenInput) + topic = None - def save(self, topic, user, ip=None): + class Media: + js = ('js/forums.js', ) + + def clean_topic_id(self): + id = self.cleaned_data['topic_id'] + print '*********', id + try: + self.topic = Topic.objects.get(pk=id) + print '******** Got a topic' + except Topic.DoesNotExist: + raise forms.ValidationError('invalid topic') + return id + + def save(self, user, ip=None): """ Creates a new post from the form data and supplied arguments. """ - post = Post(topic=topic, user=user, body=self.cleaned_data['body'], - user_ip=user_ip) + post = Post(topic=self.topic, user=user, body=self.cleaned_data['body'], + user_ip=ip) post.save() + return post class NewTopicForm(forms.Form):