changeset 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 96eec1ed0fd3
files gpp/bio/models.py gpp/forums/forms.py gpp/forums/models.py gpp/templates/forums/display_post.html
diffstat 4 files changed, 16 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- 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
--- 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
--- 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):
--- 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 @@
       <a name="p{{ post.id }}"></a>
       <a href="{% url bio-view_profile username=post.user.username %}">{{ post.user.username }}</a><br />
       {% avatar post.user %}
+      Joined: {{ post.user.date_joined|date:"M d, Y" }}<br />
+      Posts: {{ post.user.get_profile.forum_post_count }}<br />
+      Location: {{ post.user.get_profile.location }}<br />
    </td>
    <td class="forum-post-body">
       <div class="forum-post-info quiet">