Exemplo n.º 1
0
def api_author_posts(author_name):
    posts = Post.get_posts_by_author_name(author_name)
    posts = map(lambda post: dump_post(post), posts)
    posts = list(posts)
    return ok({
        'author_name': author_name,
        'posts': posts,
    })
Exemplo n.º 2
0
def posts_id_delete(id):
    try:
        post = Post.get(id=id)
    except Post.DoesNotExist:
        return error('post does not exist', 404)

    if post.magazine_posts.count():
        return error('存在关联的杂志引用,确定删除需要先删除关联的杂志引用')

    post.delete_instance()
    return ok()
Exemplo n.º 3
0
def posts_id_delete(id):
    try:
        post = Post.get(id=id)
    except Post.DoesNotExist:
        return error('post does not exist', 404)

    if post.magazine_posts.count():
        return error('存在关联的杂志引用,确定删除需要先删除关联的杂志引用')

    post.delete_instance()
    return ok()
Exemplo n.º 4
0
def posts_public(id):

    try:
        post = Post.get(id=id)
    except Post.DoesNotExist:
        return error('post does not exist', 404)

    print(post.category)

    if post.category != 'source':
        post.update_visits()

    if post.category in ('recipe', 'recipe_list'):
        return redirect(post.content)
    else:
        return render_template('posts.html', post=post)
Exemplo n.º 5
0
def posts_public(id):

    try:
        post = Post.get(id=id)
    except Post.DoesNotExist:
        return error('post does not exist', 404)

    print(post.category)

    if post.category != 'source':
        post.update_visits()

    if post.category in ('recipe', 'recipe_list'):
        return redirect(post.content)
    else:
        return render_template('posts.html', post=post)
Exemplo n.º 6
0
def posts_new():
    json_data = request.get_json()
    user_id = current_user.id
    author_name = json_data.get('author')
    category = json_data.get('category')
    title = json_data.get('title')
    content = json_data.get('content')

    if not all((author_name, category, title, content)):
        return error('没有提供所有参数')

    post = Post.create_post(user_id=user_id,
                            author_name=author_name,
                            category=category,
                            title=title,
                            content=content)
    return ok(dump_post(post, mode='only_id'))
Exemplo n.º 7
0
def posts_new():
    json_data = request.get_json()
    user_id = current_user.id
    author_name = json_data.get('author')
    category = json_data.get('category')
    title = json_data.get('title')
    content = json_data.get('content')

    if not all((author_name, category, title, content)):
        return error('没有提供所有参数')

    post = Post.create_post(
        user_id=user_id,
        author_name=author_name,
        category=category,
        title=title,
        content=content)
    return ok(dump_post(post, mode='only_id'))
Exemplo n.º 8
0
def posts_id_update(id):
    try:
        post = Post.get(id=id)
    except Post.DoesNotExist:
        return error('post does not exist', 404)

    json_data = request.get_json()

    author_name = json_data.get('author')
    category = json_data.get('category')
    title = json_data.get('title')
    content = json_data.get('content')

    if not all((author_name, category, title, content)):
        return error('没有提供所有参数')

    post.update_post(author_name=author_name,
                     category=category,
                     title=title,
                     content=content)
    return ok()
Exemplo n.º 9
0
def posts_id_update(id):
    try:
        post = Post.get(id=id)
    except Post.DoesNotExist:
        return error('post does not exist', 404)

    json_data = request.get_json()

    author_name = json_data.get('author')
    category = json_data.get('category')
    title = json_data.get('title')
    content = json_data.get('content')

    if not all((author_name, category, title, content)):
        return error('没有提供所有参数')

    post.update_post(
        author_name=author_name,
        category=category,
        title=title,
        content=content)
    return ok()
Exemplo n.º 10
0
def dump_post_list():
    posts_data = []
    posts = Post.all()
    for post in posts:
        posts_data.append(dump_post(post, mode='without_content'))
    return posts_data
Exemplo n.º 11
0
def posts_id(id):
    try:
        post = Post.get(id=id)
    except Post.DoesNotExist:
        return error('post does not exist', 404)
    return ok(dump_post(post))
Exemplo n.º 12
0
def posts_id(id):
    try:
        post = Post.get(id=id)
    except Post.DoesNotExist:
        return error('post does not exist', 404)
    return ok(dump_post(post))