comparison gpp/forums/forms.py @ 108:80ab249d1adc

Forums: quoting existing posts.
author Brian Neal <bgneal@gmail.com>
date Sat, 26 Sep 2009 03:55:50 +0000
parents cb72577785df
children c329bfaed4a7
comparison
equal deleted inserted replaced
107:e94398f5e027 108:80ab249d1adc
4 from django import forms 4 from django import forms
5 from django.conf import settings 5 from django.conf import settings
6 6
7 from forums.models import Topic 7 from forums.models import Topic
8 from forums.models import Post 8 from forums.models import Post
9
10
11 def bump_post_count(user):
12 """
13 Increments the forum_post_count for the given user.
14 """
15 profile = user.get_profile()
16 profile.forum_post_count += 1
17 profile.save()
18 9
19 10
20 class NewPostForm(forms.Form): 11 class NewPostForm(forms.Form):
21 """Form for creating a new post.""" 12 """Form for creating a new post."""
22 body = forms.CharField(label='', widget=forms.Textarea) 13 body = forms.CharField(label='', widget=forms.Textarea)
43 Creates a new post from the form data and supplied arguments. 34 Creates a new post from the form data and supplied arguments.
44 """ 35 """
45 post = Post(topic=self.topic, user=user, body=self.cleaned_data['body'], 36 post = Post(topic=self.topic, user=user, body=self.cleaned_data['body'],
46 user_ip=ip) 37 user_ip=ip)
47 post.save() 38 post.save()
48 bump_post_count(user)
49 return post 39 return post
50 40
51 41
52 class NewTopicForm(forms.Form): 42 class NewTopicForm(forms.Form):
53 """ 43 """
94 post = Post(topic=topic, 84 post = Post(topic=topic,
95 user=self.user, 85 user=self.user,
96 body=self.cleaned_data['body'], 86 body=self.cleaned_data['body'],
97 user_ip=ip) 87 user_ip=ip)
98 post.save() 88 post.save()
99
100 bump_post_count(self.user)
101 return topic 89 return topic
102 90
103 91
104 class PostForm(forms.ModelForm): 92 class PostForm(forms.ModelForm):
105 """ 93 """
106 Form for editing an existing post. 94 Form for editing an existing post or a new, non-quick post.
107 """ 95 """
108 body = forms.CharField(label='', widget=forms.Textarea) 96 body = forms.CharField(label='', widget=forms.Textarea)
109 97
110 class Meta: 98 class Meta:
111 model = Post 99 model = Post