Ejemplo n.º 1
0
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
Ejemplo n.º 2
0
    def thread(self, id, category_id, thread_id):
        c.thread_id = thread_id
        c.category_id = category_id
        c.can_manage_post = self.can_manage_post
        forum_posts = meta.Session.query(ForumPost)\
            .filter_by(category_id=category_id,
                       thread_id=thread_id,
                       deleted_by=None)\
            .order_by(ForumPost.created_on)
        c.forum_posts = paginate.Page(
            forum_posts,
            url=url,
            page=int(request.params.get('page', 1)),
            item_count = forum_posts.count(),
            items_per_page = 20,
            )

        subscription = SubscribedThread.get(thread_id, c.user)
        c.subscribed = subscription and subscription.active

        c.first_unseen = c.thread.first_unseen_thread_post(c.user)
        c.thread.mark_as_seen_by(c.user)

        return render('forum/thread.mako')
Ejemplo n.º 3
0
 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))