diff gpp/forums/tools.py @ 390:e0523e17ea43

Fixing #175; add an auto-subscribe and auto-favorite forum topic feature. Added 2 flags to the user profile. Added 2 functions that are called on the post post-save signal that auto-favorite and auto-subscribe the post creator if they have requested this service.
author Brian Neal <bgneal@gmail.com>
date Mon, 21 Mar 2011 00:39:52 +0000
parents d1b11096595b
children
line wrap: on
line diff
--- a/gpp/forums/tools.py	Sun Mar 20 20:23:29 2011 +0000
+++ b/gpp/forums/tools.py	Mon Mar 21 00:39:52 2011 +0000
@@ -106,3 +106,25 @@
             body=post_body,
             user_ip=ip)
     post.save()
+
+
+def auto_favorite(post):
+    """
+    Given a newly created post, perform an auto-favorite action if the post
+    creator has that option set in their profile.
+
+    """
+    profile = post.user.get_profile()
+    if profile.auto_favorite:
+        post.topic.bookmarkers.add(post.user)
+
+
+def auto_subscribe(post):
+    """
+    Given a newly created post, perform an auto-subscribe action if the post
+    creator has that option set in their profile.
+
+    """
+    profile = post.user.get_profile()
+    if profile.auto_subscribe:
+        post.topic.subscribers.add(post.user)