コード例 #1
0
ファイル: test_prod.py プロジェクト: anuscode/blanc-server
    def test_list_posts(self):
        posts = Post.objects.skip(2).limit(2).all()
        posts = Post.list_posts()
        response = list(posts)
        print(response)

        if __name__ == "__main__":
            unittest.main()
コード例 #2
0
def route_list_posts():
    uid = request.headers.get("uid", None)
    user = User.get(uid=uid)
    opposite_sex = "M" if user.sex == "F" else "F"

    last_id: str = request.args.get("last_id", None)
    per_page: int = int(request.args.get("per_page", 30))

    params = dict(author_sex=opposite_sex, limit=per_page, is_deleted=False)
    if last_id:
        params["id__lt"] = last_id

    result = Post.list_posts(**params)

    response = encode(list(result))
    return Response(response, mimetype="application/json")
コード例 #3
0
def route_list_posts():
    """Lists all posts not filtering opposite sex things."""
    uid = request.headers.get("uid", None)
    admin = Admin.objects.get_or_404(uid=uid)

    if not admin.available:
        abort(401)

    last_id: str = request.args.get("last_id", None)
    per_page: int = int(request.args.get("per_page", 30))

    params = dict(is_deleted=False, limit=per_page)
    if last_id:
        params["id__lt"] = last_id

    result = Post.list_posts(**params)

    response = encode(list(result))
    return Response(response, mimetype="application/json")