Ejemplo n.º 1
0
def subscribed():
    page = int(request.args.get('page', 1))
    page_length = app.config['PAGE_LENGTH']

    posts = set()

    user_id = current_user.id
    user_subs = m.Subscription.query.filter(
        and_(
            m.Subscription.user_id == user_id,
            m.Subscription.is_deleted == False
        )
    ).all()
    for sub in user_subs:
        criteria = "true"
        for tag in sub.tags:
            criteria = and_(criteria, m.Post.tags.contains(tag))
        if sub.subscribee is not None:
            criteria = and_(criteria, m.Post.created_by_id == sub.subscribee.id)

        # if criteria is still "true", then no filters
        # were applied, and no posts should be returned
        if criteria == "true":
            criteria = "false"

        sub_posts = m.Post.query.filter(criteria).all()
        posts |= set(sub_posts)

    postlist = list(posts)
    response = serialize_and_paginate(postlist, page_length, page)
    return jsonify(response), 200
Ejemplo n.º 2
0
def post_revisions(post_id):
    page = int(request.args.get('page', 1))
    page_length = app.config['PAGE_LENGTH']
    post = m.Post.query.get(post_id)
    if post is None:
        return jsonify(error='There is no post with id ' + str(post_id)), 400
    response = serialize_and_paginate(post.revisions, page_length, page)
    return jsonify(response), 200
Ejemplo n.º 3
0
def subscriptions():
    user_id = current_user.id
    page = int(request.args.get('page', 1))
    user_subs = m.Subscription.query.filter(
        and_(
            m.Subscription.user_id == user_id,
            m.Subscription.is_deleted == False
        )
    ).all()
    response = serialize_and_paginate(user_subs, app.config['PAGE_LENGTH'], page)
    return jsonify(response), 200