Ejemplo n.º 1
0
def boards():
    data = request.args
    page = int(data.get('page', 0))
    per_page = int(data.get('per_page', 20))
    boards = Models.Board.objects(status="PUBLISHED")
    res = paginate(boards, page, per_page)

    return jsonify(message='OK', boards=[Json.board_json(r) for r in res])
def items():
    query = refactor_query(request.args)
    page = query.pop('page', 0)
    per_page = query.pop('per_page', 20)

    objects = Models.Item.available_items(**query)
    items = paginate(objects, page, per_page)
    data=[Json.item_json_in_list(i) for i in items]
    return jsonify(message='OK', items=data, total=objects.count())
Ejemplo n.º 3
0
def posts():
    query = refactor_query(request.args)
    page = query.pop('page', 0)
    per_page = query.pop('per_page', 20)

    objects = Models.Post.approved_posts(**query)
    posts = paginate(objects, page, per_page)
    data = [Json.post_json(p) for p in posts]
    return jsonify(message='OK', posts=data, total=objects.count())
Ejemplo n.º 4
0
def post_likes(post_id):
    data = request.args
    page = int(data.get('page', 0))
    per_page = int(data.get('per_page', 20))
    post = Models.Post.objects(post_id=post_id).first_or_404()

    objects = Models.PostLike.objects(post=post)
    likes = paginate(objects, page, per_page)

    return jsonify(message='OK', users=[Json.user_json(l.user) for l in likes])
Ejemplo n.º 5
0
def like_posts():
    data = request.args
    user_id = data.get('user_id', current_user._get_current_object().id)
    page = int(data.get('page', 0))
    per_page = int(data.get('per_page', 20))

    objects = Models.PostLike.objects(user_id=user_id)
    likes = paginate(objects, page, per_page)

    return jsonify(message='OK', posts=[Json.post_json(l.post) for l in likes])
Ejemplo n.º 6
0
def user_followings():
    args = request.args
    user_id = args.get('user_id')
    page = int(args.get('page', 0))
    per_page = int(args.get('per_page', 20))

    user = Models.User.objects(id=user_id).first_or_404()
    followings = user.followings
    users = paginate(followings, page, per_page)

    return jsonify(message='OK', users=[Json.user_json(u) for u in users])
Ejemplo n.º 7
0
def get_activities():
    data = request.args
    user_id = data.get('user_id', current_user._get_current_object().id)
    page = int(data.get('page', 0))
    per_page = int(data.get('per_page', 20))

    objects = Models.PostActivity.objects(to_user_id=user_id)
    activities = paginate(objects, page, per_page)

    return jsonify(message='OK',
                   notices=[Json.noti_json(ac) for ac in activities])