Exemplo n.º 1
0
def forum_posts(connect):
    cursor = connect.cursor(cursor_class=MySQLCursorDict)

    req_args = ['forum']
    opt_args = ['since', 'limit', 'sort', 'order']
    short_name = extract_req(request.args, req_args)
    since, limit, sort, order = extract_opt(request.args, opt_args)

    related = extract_list(request.args, 'related',
                           ['user', 'forum', 'thread'])

    forum = get_forum_by_slug(cursor, short_name)
    posts = get_forum_posts(cursor, short_name, since, limit, sort, order)

    for post in posts:
        if 'user' in related:
            post['user'] = get_user_by_email(cursor, post['user'])

        if 'forum' in related:
            post.update({'forum': forum})

        if 'thread' in related:
            post['thread'] = get_thread_by_id(cursor, post['thread'])

    cursor.close()
    return response_ok(posts)
Exemplo n.º 2
0
def thread_vote(connect):
    cursor = connect.cursor(cursor_class=MySQLCursorDict)

    req_args = ['vote', 'thread']
    vote, thread = extract_req(request.get_json(force=True), req_args)

    set_thread_vote(cursor, thread, vote)
    connect.commit()

    thread = get_thread_by_id(cursor, thread)
    cursor.close()
    return response_ok(thread)
Exemplo n.º 3
0
def thread_update(connect):
    cursor = connect.cursor(cursor_class=MySQLCursorDict)

    req_args = ['message', 'slug', 'thread']
    message, slug, thread = extract_req(request.get_json(force=True), req_args)

    set_thread_message_slug(cursor, thread, message, slug)
    connect.commit()

    thread = get_thread_by_id(cursor, thread)
    cursor.close()
    return response_ok(thread)
Exemplo n.º 4
0
def thread_vote(connect):
    cursor = connect.cursor(cursor_class=MySQLCursorDict)

    req_args = ['vote', 'thread']
    vote, thread = extract_req(request.get_json(force=True), req_args)

    set_thread_vote(cursor, thread, vote)
    connect.commit()

    thread = get_thread_by_id(cursor, thread)
    cursor.close()
    return response_ok(thread)
Exemplo n.º 5
0
def thread_update(connect):
    cursor = connect.cursor(cursor_class=MySQLCursorDict)

    req_args = ['message', 'slug', 'thread']
    message, slug, thread = extract_req(request.get_json(force=True), req_args)

    set_thread_message_slug(cursor, thread, message, slug)
    connect.commit()

    thread = get_thread_by_id(cursor, thread)
    cursor.close()
    return response_ok(thread)
Exemplo n.º 6
0
def thread_details(connect):
    cursor = connect.cursor(cursor_class=MySQLCursorDict)

    req_args = ['thread']
    thread = extract_req(request.args, req_args)
    related = extract_list(request.args, 'related', ['user', 'forum'])

    thread = get_thread_by_id(cursor, thread)

    if 'user' in related:
        thread['user'] = get_user_by_email(cursor, thread['user'])

    if 'forum' in related:
        thread['forum'] = get_forum_by_slug(cursor, thread['forum'])

    cursor.close()
    return response_ok(thread)
Exemplo n.º 7
0
def thread_details(connect):
    cursor = connect.cursor(cursor_class=MySQLCursorDict)

    req_args = ['thread']
    thread = extract_req(request.args, req_args)
    related = extract_list(request.args, 'related', ['user', 'forum'])

    thread = get_thread_by_id(cursor, thread)

    if 'user' in related:
        thread['user'] = get_user_by_email(cursor, thread['user'])

    if 'forum' in related:
        thread['forum'] = get_forum_by_slug(cursor, thread['forum'])

    cursor.close()
    return response_ok(thread)
Exemplo n.º 8
0
def post_details(connect):
    cursor = connect.cursor(cursor_class=MySQLCursorDict)

    req_args = ['post']
    post = extract_req(request.args, req_args)
    related = extract_list(request.args, 'related', ['user', 'forum', 'thread'])

    post = get_post_by_id(cursor, post)

    if 'user' in related:
        post['user'] = get_user_by_email(cursor, post['user'])

    if 'forum' in related:
        post['forum'] = get_forum_by_slug(cursor, post['forum'])

    if 'thread' in related:
        post['thread'] = get_thread_by_id(cursor, post['thread'])

    cursor.close()
    return response_ok(post)
Exemplo n.º 9
0
def post_details(connect):
    cursor = connect.cursor(cursor_class=MySQLCursorDict)

    req_args = ['post']
    post = extract_req(request.args, req_args)
    related = extract_list(request.args, 'related',
                           ['user', 'forum', 'thread'])

    post = get_post_by_id(cursor, post)

    if 'user' in related:
        post['user'] = get_user_by_email(cursor, post['user'])

    if 'forum' in related:
        post['forum'] = get_forum_by_slug(cursor, post['forum'])

    if 'thread' in related:
        post['thread'] = get_thread_by_id(cursor, post['thread'])

    cursor.close()
    return response_ok(post)