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())
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())
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])
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])
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])
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])