示例#1
0
def listPosts_forum():
    forum_short_name = request.args.get("forum")
    if forum_short_name:
        entity = "forum"
        var = forum_short_name
    else:
        return json.dumps(responses_codes[2], sort_keys=True)
    related = request.args.getlist("related")
    since = request.args.get("since")
    limit = request.args.get("limit")
    order = request.args.get("order")
    results = {
        "code": 0,
        "response": list_posts(related, since, limit, order, entity, var)
    }
    return json.dumps(results, sort_keys=True)
示例#2
0
def listPosts_forum_user():
    email = request.args.get("user")
    if email:
        entity = "user"
        var = email
    else:
        return json.dumps(responses_codes[2], sort_keys=True)
    related = request.args.getlist("related")
    since = request.args.get("since")
    limit = request.args.get("limit")
    order = request.args.get("order")
    results = {
        "code": 0,
        "response": list_posts(related, since, limit, order, entity, var)
    }
    return json.dumps(results, sort_keys=True)
示例#3
0
def listPosts_forum():
    forum_short_name = request.args.get("forum")
    if forum_short_name:
        entity = "forum"
        var = forum_short_name
    else:
        return json.dumps(responses_codes[2], sort_keys=True)
    related = request.args.getlist("related")
    since = request.args.get("since")
    limit = request.args.get("limit")
    order = request.args.get("order")
    results = {
        "code": 0,
        "response": list_posts(related, since, limit, order, entity, var)
    }
    return json.dumps(results, sort_keys=True)
示例#4
0
def listPosts_thread():
    tree_posts_list = []
    cur = mysql.connection.cursor()

    thread_id = request.args.get("thread")
    if not thread_id:
        return json.dumps(responses_codes[2], sort_keys=True)
    sort = request.args.get("sort")
    since = request.args.get("since")
    limit = request.args.get("limit")
    order = request.args.get("order")

    if sort is None or sort == 'flat':
        results = {
            "code": 0,
            "response": list_posts([], since, limit, order, "thread", thread_id)
        }
        return json.dumps(results, sort_keys=True)

    if sort not in ['flat', 'tree', 'parent_tree']:
        return json.dumps(responses_codes[2], sort_keys=True)

    query = '''SELECT path FROM Post WHERE thread = '%s' '''
    query_params = (thread_id,)
    if since:
        query += "AND date >= '%s' "
        query_params += (since,)

    cur.execute(query % query_params)
    for x in cur.fetchall():
        tree_posts_list.append(x[0])

    tree_posts_list = natural_sort(tree_posts_list)

    if order is None or order == 'desc':
        tree_posts_list = sorted(tree_posts_list, key=lambda k: int(k.split('.')[0]), reverse=True)

    if limit and int(limit) <= len(tree_posts_list):
        n = int(limit)
    else:
        n = len(tree_posts_list)

    x = 0
    result_set = []
    if sort == 'tree':
        while x < n:
            split_list = tree_posts_list[x].split('.')
            result_set.append(get_post_entity([], int(split_list[len(split_list)-1])))
            x+=1
    else:
        i = 0
        prev_firs_id = tree_posts_list[0].split('.')[0]
        while x < n and i < len(tree_posts_list):
            split_list = tree_posts_list[i].split('.')
            if split_list[0] != prev_firs_id:
                x += 1
            if x < n:
                result_set.append(get_post_entity([], int(split_list[len(split_list)-1])))
            prev_firs_id = tree_posts_list[i].split('.')[0]
            i+=1

    results = {
        "code": 0,
        "response": result_set
    }
    return json.dumps(results, sort_keys=True)
示例#5
0
def listPosts_thread():
    tree_posts_list = []
    cur = mysql.connection.cursor()

    thread_id = request.args.get("thread")
    if not thread_id:
        return json.dumps(responses_codes[2], sort_keys=True)
    sort = request.args.get("sort")
    since = request.args.get("since")
    limit = request.args.get("limit")
    order = request.args.get("order")

    if sort is None or sort == 'flat':
        results = {
            "code": 0,
            "response": list_posts([], since, limit, order, "thread", thread_id)
        }
        return json.dumps(results, sort_keys=True)

    if sort not in ['flat', 'tree', 'parent_tree']:
        return json.dumps(responses_codes[2], sort_keys=True)

    query = '''SELECT path FROM Post WHERE thread = '%s' '''
    query_params = (thread_id,)
    if since:
        query += "AND date >= '%s' "
        query_params += (since,)

    cur.execute(query % query_params)
    for x in cur.fetchall():
        tree_posts_list.append(x[0])

    tree_posts_list = natural_sort(tree_posts_list)

    if order is None or order == 'desc':
        tree_posts_list = sorted(tree_posts_list, key=lambda k: int(k.split('.')[0]), reverse=True)

    if limit and int(limit) <= len(tree_posts_list):
        n = int(limit)
    else:
        n = len(tree_posts_list)

    x = 0
    result_set = []
    if sort == 'tree':
        while x < n:
            split_list = tree_posts_list[x].split('.')
            result_set.append(get_post_entity([], int(split_list[len(split_list)-1])))
            x += 1
    else:
        if tree_posts_list != []:
            i = 0
            prev_firs_id = tree_posts_list[0].split('.')[0]
            while x < n and i < len(tree_posts_list):
                split_list = tree_posts_list[i].split('.')
                if split_list[0] != prev_firs_id:
                    x+=1
                if x < n:
                    result_set.append(get_post_entity([], int(split_list[len(split_list)-1])))
                prev_firs_id = tree_posts_list[i].split('.')[0]
                i+=1

    results = {
        "code": 0,
        "response": result_set
    }
    return json.dumps(results, sort_keys=True)