Mercurial > public > sg101
comparison gpp/forums/forms.py @ 96:93d9e74a471e
Forums: added forum post counts for each user in the user profile.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Sun, 13 Sep 2009 18:43:08 +0000 |
parents | 23035afdeae8 |
children | eb9f99382476 |
comparison
equal
deleted
inserted
replaced
95:23035afdeae8 | 96:93d9e74a471e |
---|---|
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() | |
9 | 18 |
10 | 19 |
11 class PostForm(forms.Form): | 20 class PostForm(forms.Form): |
12 """Form for creating a new post.""" | 21 """Form for creating a new post.""" |
13 body = forms.CharField(label='', widget=forms.Textarea) | 22 body = forms.CharField(label='', widget=forms.Textarea) |
36 Creates a new post from the form data and supplied arguments. | 45 Creates a new post from the form data and supplied arguments. |
37 """ | 46 """ |
38 post = Post(topic=self.topic, user=user, body=self.cleaned_data['body'], | 47 post = Post(topic=self.topic, user=user, body=self.cleaned_data['body'], |
39 user_ip=ip) | 48 user_ip=ip) |
40 post.save() | 49 post.save() |
50 bump_post_count(user) | |
41 return post | 51 return post |
42 | 52 |
43 | 53 |
44 class NewTopicForm(forms.Form): | 54 class NewTopicForm(forms.Form): |
45 """Form for creating a new topic and 1st post to that topic.""" | 55 """Form for creating a new topic and 1st post to that topic.""" |
68 user=user, | 78 user=user, |
69 body=self.cleaned_data['body'], | 79 body=self.cleaned_data['body'], |
70 user_ip=ip) | 80 user_ip=ip) |
71 post.save() | 81 post.save() |
72 | 82 |
83 bump_post_count(user) | |
73 return topic | 84 return topic |