# HG changeset patch # User Brian Neal # Date 1252867388 0 # Node ID 93d9e74a471ef60eb951b82d96ce78c4c4c829fc # Parent 23035afdeae816a716e703c7556933f20bc50995 Forums: added forum post counts for each user in the user profile. diff -r 23035afdeae8 -r 93d9e74a471e gpp/bio/models.py --- a/gpp/bio/models.py Sun Sep 13 18:05:18 2009 +0000 +++ b/gpp/bio/models.py Sun Sep 13 18:43:08 2009 +0000 @@ -36,6 +36,7 @@ avatar = models.ImageField(upload_to=avatar_file_path, blank=True) time_zone = models.CharField(max_length=64, blank=True, default='US/Pacific') + forum_post_count = models.IntegerField(default=0) def __unicode__(self): return self.user.username diff -r 23035afdeae8 -r 93d9e74a471e gpp/forums/forms.py --- a/gpp/forums/forms.py Sun Sep 13 18:05:18 2009 +0000 +++ b/gpp/forums/forms.py Sun Sep 13 18:43:08 2009 +0000 @@ -8,6 +8,15 @@ from forums.models import Post +def bump_post_count(user): + """ + Increments the forum_post_count for the given user. + """ + profile = user.get_profile() + profile.forum_post_count += 1 + profile.save() + + class PostForm(forms.Form): """Form for creating a new post.""" body = forms.CharField(label='', widget=forms.Textarea) @@ -38,6 +47,7 @@ post = Post(topic=self.topic, user=user, body=self.cleaned_data['body'], user_ip=ip) post.save() + bump_post_count(user) return post @@ -70,4 +80,5 @@ user_ip=ip) post.save() + bump_post_count(user) return topic diff -r 23035afdeae8 -r 93d9e74a471e gpp/forums/models.py --- a/gpp/forums/models.py Sun Sep 13 18:05:18 2009 +0000 +++ b/gpp/forums/models.py Sun Sep 13 18:43:08 2009 +0000 @@ -119,7 +119,7 @@ user_ip = models.IPAddressField(blank=True, default='', null=True) class Meta: - ordering = ('creation_date', ) + ordering = ('-creation_date', ) @models.permalink def get_absolute_url(self): diff -r 23035afdeae8 -r 93d9e74a471e gpp/templates/forums/display_post.html --- a/gpp/templates/forums/display_post.html Sun Sep 13 18:05:18 2009 +0000 +++ b/gpp/templates/forums/display_post.html Sun Sep 13 18:43:08 2009 +0000 @@ -4,6 +4,9 @@ {{ post.user.username }}
{% avatar post.user %} + Joined: {{ post.user.date_joined|date:"M d, Y" }}
+ Posts: {{ post.user.get_profile.forum_post_count }}
+ Location: {{ post.user.get_profile.location }}