Beispiel #1
0
def magazines_mid_posts_id_update(mid, id):
    try:
        magazine_post = MagazinePost.get(MagazinePost.id == id)
    except MagazinePost.DoesNotExist:
        return error('magazine_post does not exist', 404)

    json_data = request.get_json()

    user_id = current_user.id
    magazine_id = mid
    post_id = id

    title = json_data.get('title')
    desc = json_data.get('desc')
    cover = json_data.get('cover')
    category = json_data.get('category')
    category_icon = json_data.get('category_icon')

    if not all(
        (magazine_id, post_id, title, desc, cover, category, category_icon)):
        return error('没有提供所有参数')

    magazine_post.update_magazine_post(user_id=user_id,
                                       magazine_id=magazine_id,
                                       post_id=post_id,
                                       title=title,
                                       desc=desc,
                                       cover=cover,
                                       category=category,
                                       category_icon=category_icon)
    return ok()
Beispiel #2
0
def magazines_mid_posts_id_update(mid, id):
    try:
        magazine_post = MagazinePost.get(MagazinePost.id == id)
    except MagazinePost.DoesNotExist:
        return error('magazine_post does not exist', 404)

    json_data = request.get_json()

    user_id = current_user.id
    magazine_id = mid
    post_id = id

    title = json_data.get('title')
    desc = json_data.get('desc')
    cover = json_data.get('cover')
    category = json_data.get('category')
    category_icon = json_data.get('category_icon')

    if not all((magazine_id, post_id, title, desc, cover,
               category, category_icon)):
        return error('没有提供所有参数')

    magazine_post.update_magazine_post(
        user_id=user_id,
        magazine_id=magazine_id,
        post_id=post_id,
        title=title,
        desc=desc,
        cover=cover,
        category=category,
        category_icon=category_icon)
    return ok()
Beispiel #3
0
def login():
    json_data = request.get_json()
    try:
        user = User.get(username=json_data.get('username'))
    except User.DoesNotExist:
        return error((211, 'Could not find user'))
    if not user.verify_password(json_data.get('password')):
        return error((210, 'The username and password mismatch.'))
    login_user(user)
    return ok(dump_user(user))
Beispiel #4
0
def magazines_id_delete(id):
    try:
        magazine = Magazine.get(Magazine.id == id)
    except Magazine.DoesNotExist:
        return error('magazine does not exist', 404)

    if magazine.posts.count():
        return error('杂志中有文章,确定删除请先删除杂志中的内容')

    magazine.delete_instance()
    return ok()
Beispiel #5
0
def login():
    json_data = request.get_json()
    try:
        user = User.get(
            username=json_data.get('username'))
    except User.DoesNotExist:
        return error((211, 'Could not find user'))
    if not user.verify_password(json_data.get('password')):
        return error((210, 'The username and password mismatch.'))
    login_user(user)
    return ok(dump_user(user))
Beispiel #6
0
def magazines_id_delete(id):
    try:
        magazine = Magazine.get(Magazine.id == id)
    except Magazine.DoesNotExist:
        return error('magazine does not exist', 404)

    if magazine.posts.count():
        return error('杂志中有文章,确定删除请先删除杂志中的内容')

    magazine.delete_instance()
    return ok()
Beispiel #7
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()
Beispiel #8
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()
Beispiel #9
0
def magazines_id_update(id):
    try:
        magazine = Magazine.get(Magazine.id == id)
    except Magazine.DoesNotExist:
        return error('magazine does not exist', 404)

    json_data = request.get_json()

    title = json_data.get('title')

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

    magazine.update_magazine(title=title)
    return ok()
Beispiel #10
0
def magazines_id_update(id):
    try:
        magazine = Magazine.get(Magazine.id == id)
    except Magazine.DoesNotExist:
        return error('magazine does not exist', 404)

    json_data = request.get_json()

    title = json_data.get('title')

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

    magazine.update_magazine(title=title)
    return ok()
Beispiel #11
0
def magazines_public(mid):
    try:
        magazine = Magazine.get(Magazine.id == mid)
    except Magazine.DoesNotExist:
        return error('magazine does not exist', 404)

    return render_template('magazine.html', magazine=dump_magazine(magazine))
Beispiel #12
0
def magazines_id(id):
    try:
        magazine = Magazine.get(Magazine.id == id)
    except Magazine.DoesNotExist:
        return error('magazine does not exist', 404)

    return ok(dump_magazine(magazine))
Beispiel #13
0
def magazines_mid_posts_new(mid):
    json_data = request.get_json()

    user_id = current_user.id
    magazine_id = mid
    post_id = json_data.get('post_id')
    title = json_data.get('title')
    desc = json_data.get('desc')
    cover = json_data.get('cover')
    category = json_data.get('category')
    category_icon = json_data.get('category_icon')

    if not all((magazine_id, post_id, title, cover,
               category, category_icon)):
        return error('没有提供所有参数')

    magazine_post = MagazinePost.create_magazine_post(
        user_id=user_id,
        magazine_id=magazine_id,
        post_id=post_id,
        title=title,
        desc=desc,
        cover=cover,
        category=category,
        category_icon=category_icon)
    return ok(dump_magazine_post(magazine_post, mode='only_id'))
Beispiel #14
0
def magazines_mid_posts_new(mid):
    json_data = request.get_json()

    user_id = current_user.id
    magazine_id = mid
    post_id = json_data.get('post_id')
    title = json_data.get('title')
    desc = json_data.get('desc')
    cover = json_data.get('cover')
    category = json_data.get('category')
    category_icon = json_data.get('category_icon')

    if not all((magazine_id, post_id, title, cover, category, category_icon)):
        return error('没有提供所有参数')

    magazine_post = MagazinePost.create_magazine_post(
        user_id=user_id,
        magazine_id=magazine_id,
        post_id=post_id,
        title=title,
        desc=desc,
        cover=cover,
        category=category,
        category_icon=category_icon)
    return ok(dump_magazine_post(magazine_post, mode='only_id'))
Beispiel #15
0
def magazines_public(mid):
    try:
        magazine = Magazine.get(Magazine.id == mid)
    except Magazine.DoesNotExist:
        return error('magazine does not exist', 404)

    return render_template('magazine.html', magazine=dump_magazine(magazine))
Beispiel #16
0
def magazines_id(id):
    try:
        magazine = Magazine.get(Magazine.id == id)
    except Magazine.DoesNotExist:
        return error('magazine does not exist', 404)

    return ok(dump_magazine(magazine))
Beispiel #17
0
def magazines_mid_posts_id_delete(mid, id):
    try:
        magazine_post = MagazinePost.get(MagazinePost.id == id)
    except MagazinePost.DoesNotExist:
        return error('magazine_post does not exist', 404)

    magazine_post.delete_instance()
    return ok()
Beispiel #18
0
def magazines_mid_posts_id_delete(mid, id):
    try:
        magazine_post = MagazinePost.get(MagazinePost.id == id)
    except MagazinePost.DoesNotExist:
        return error('magazine_post does not exist', 404)

    magazine_post.delete_instance()
    return ok()
Beispiel #19
0
def magazines_new():
    json_data = request.get_json()

    title = json_data.get('title')

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

    magazine = Magazine.create_magazine(title=title)
    return ok(dump_magazine(magazine, mode='only_id'))
Beispiel #20
0
def magazines_new():
    json_data = request.get_json()

    title = json_data.get('title')

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

    magazine = Magazine.create_magazine(
        title=title)
    return ok(dump_magazine(magazine, mode='only_id'))
Beispiel #21
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()
Beispiel #22
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()
Beispiel #23
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)
Beispiel #24
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)
Beispiel #25
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'))
Beispiel #26
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'))
Beispiel #27
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))
Beispiel #28
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))
Beispiel #29
0
def magazines_mid_posts_id(mid, id):
    try:
        magazine_post = MagazinePost.get(MagazinePost.id == id)
    except MagazinePost.DoesNotExist:
        return error('magazine_post does not exist', 404)
    return ok(dump_magazine_post(magazine_post))
Beispiel #30
0
def magazines_mid_posts_id(mid, id):
    try:
        magazine_post = MagazinePost.get(MagazinePost.id == id)
    except MagazinePost.DoesNotExist:
        return error('magazine_post does not exist', 404)
    return ok(dump_magazine_post(magazine_post))