def make_forum_post(user, title, message, group_id, category_id, thread_id=None, controller=None): new_thread = thread_id is None post = ForumPost(title, message, category_id=category_id, thread_id=thread_id) meta.Session.add(post) meta.Session.commit() meta.Session.refresh(post) # Subscribe logged in user to the thread subscription = SubscribedThread.get_or_create(post.thread_id, user, activate=True) # If this is a new thread; automatically subscribe all # interested members. if group_id and new_thread: group = Group.get(group_id) for member in group.members: if member.subscribed_to_forum: SubscribedThread.get_or_create(post.thread_id, member.user, activate=True) _send_emails(user, post, group_id, category_id, controller=controller) return post
def unsubscribe(self, id, category_id, thread_id): subscription = SubscribedThread.get_or_create(thread_id, c.user) subscription.active = False meta.Session.commit() redirect(url(controller=c.controller, action='thread', id=id, category_id=category_id, thread_id=c.thread.thread_id))