Ejemplo n.º 1
0
def posts_from_user_paginate(user, user_to_fetch):
    posts = db.session.query(Post, func.sum(Hot.number))\
        .outerjoin(Hot) \
        .filter(Post.user_id == user_to_fetch.id,
                Post.active == True,
                Post.approved == APPROVED) \
        .order_by(Post.date.desc())\
        .group_by(Post.id) \
        .all()
    response = []
    for i, (post, hot_value) in enumerate(posts):
        post.hot_value = hot_value if hot_value is not None else 0
        post.hot_up = user_had_hot_up(post, user)
        post.comments_value = len(post.comments.all())
        response.append(post)
    return response
Ejemplo n.º 2
0
def news_feed_for_user(user, **kwargs):
    page = kwargs.pop('page', 1)
    limit = kwargs.pop('limit', 50)
    posts = db.session.query(Post, func.sum(Hot.number))\
        .outerjoin(Hot) \
        .filter(Subscription.user_id == user.id,
                Subscription.group_id == Group.id,
                Post.group_id == Group.id,
                Group.active == True,
                Post.active == True,
                Post.approved == APPROVED) \
        .order_by(Post.date.desc())\
        .group_by(Post.id) \
        .limit(limit)\
        .offset((page - 1) * limit)\
        .all()
    response = []
    for i, (post, hot_value) in enumerate(posts):
        post.hot_value = hot_value if hot_value is not None else 0
        post.hot_up = user_had_hot_up(post, user)
        post.comments_value = len(post.comments.all())
        response.append(post)
    return response
Ejemplo n.º 3
0
def search_posts_with_string(user, search_string, **kwargs):
    page = kwargs.pop('page', 1)
    limit = kwargs.pop('limit', 50)
    posts_query = db.session.query(Post, func.sum(Hot.number))
    posts = search(posts_query, search_string)\
        .outerjoin(Hot) \
        .order_by(Post.date.desc())\
        .group_by(Post.id) \
        .limit(limit)\
        .offset((page - 1) * limit)\
        .all()
    response = []
    for i, (post, hot_value) in enumerate(posts):

        post.hot_value = hot_value if hot_value is not None else 0
        post.comments_value = len(post.comments.all())
        post.hot_up = user_had_hot_up(post, user)
        if post.group.active is True and \
                        post.active is True and \
                        post.approved == APPROVED and \
                        user_can_join_group_returning_bool(user, post.group):
            response.append(post)
    return response