Пример #1
0
def list_posts(request):
    if request.method == "GET":
        request_info = GET_parameters(request)
        required_info = ["user"]
        opt = get_opt(request_info=request_info, possible_values=["limit", "order", "since"])
        try:
            test_require(data=request_info, required=required_info)
            posts_array = posts.posts_list(table_="user", parametr=request_info["user"], related=[], params=opt)
        except Exception as e:
            return return_error(e.message)
        return return_response(posts_array)
    else:
        return HttpResponse(status=400)
Пример #2
0
def list_users(request):
    if request.method == "GET":
        request_info = GET_parameters(request)
        required_info = ["forum"]
        opt = get_opt(request_info=request_info, possible_values=["limit", "order", "since_id"])
        try:
            test_require(data=request_info, required=required_info)
            users_array = forums.list_users(request_info["forum"], opt)
        except Exception as e:
            return return_error(e.message)
        return return_response(users_array)
    else:
        return HttpResponse(status=400)
Пример #3
0
def list_following(request):
    if request.method == "GET":
        request_info = GET_parameters(request)
        required_info = ["user"]
        followers_opt = get_opt(request_info=request_info, possible_values=["limit", "order", "since_id"])
        try:
            test_require(data=request_info, required=required_info)
            followings_array = followers.followers_list(email=request_info["user"], type="followee", params=followers_opt)
        except Exception as e:
            return return_error(e.message)
        return return_response(followings_array)
    else:
        return HttpResponse(status=400)
Пример #4
0
def create(request):
    if request.method == "POST":
        request_info = json.loads(request.body)
        required_info = ["email", "username", "name", "about"]
        opt = get_opt(request_info=request_info, possible_values=["isAnonymous"])
        try:
            test_require(data=request_info, required=required_info)
            new_user = users.add_users(email=request_info["email"], username=request_info["username"],
                               about=request_info["about"], name=request_info["name"], optional=opt)
        except Exception as e:
            return return_error(e.message)
        return return_response(new_user)
    else:
        return HttpResponse(status=400)
Пример #5
0
def list_threads(request):
    if request.method == "GET":
        request_info = GET_parameters(request)
        required_info = ["forum"]
        relate = get_relate(request_info)
        opt = get_opt(request_info=request_info, possible_values=["limit", "order", "since"])
        try:
            test_require(data=request_info, required=required_info)
            threads_array = threads.threads_list(table_="forum", parametr=request_info["forum"],
                                             related=relate, params=opt)
        except Exception as e:
            return return_error(e.message)
        return return_response(threads_array)
    else:
        return HttpResponse(status=400)
Пример #6
0
def create(request):
    if request.method == "POST":
        request_info = json.loads(request.body)
        required_info = ["user", "forum", "thread", "message", "date"]
        optional_info = ["parent", "isApproved", "isHighlighted", "isEdited", "isSpam", "isDeleted"]
        opt = get_opt(request_info=request_info, possible_values=optional_info)
        try:
            test_require(data=request_info, required=required_info)
            post = posts.create(date=request_info["date"], thread=request_info["thread"],
                                message=request_info["message"], user=request_info["user"],
                                forum=request_info["forum"], opt=opt)
        except Exception as e:
            return return_error(e.message)
        return return_response(post)
    else:
        return HttpResponse(status=400)
Пример #7
0
def create(request):
    if request.method == "POST":

        request_info = json.loads(request.body)
        required_info = ["forum", "title", "isClosed", "user", "date", "message", "slug"]
        opt = get_opt(request_info=request_info, possible_values=["isDeleted"])
        try:
            test_require(data=request_info, required=required_info)
            new_thread = threads.add_threads(forum=request_info["forum"], title=request_info["title"], isClosed=request_info["isClosed"],
                                     user=request_info["user"], date=request_info["date"], message=request_info["message"],
                                     slug=request_info["slug"], optional=opt)
        except Exception as e:
            return return_error(e.message)
        return return_response(new_thread)
    else:
        return HttpResponse(status=400)
Пример #8
0
def threads_list(request):
    if request.method == "GET":
        request_info = GET_parameters(request)
        param = None
        try:
            param = request_info["forum"]
            table_name = "forum"
        except KeyError:
            try:
                param = request_info["user"]
                table_name = "user"
            except KeyError:
                return return_error("No user or forum parameters setted")
        opt = get_opt(request_info=request_info, possible_values=["limit", "order", "since"])
        try:
            threads_array = threads.threads_list(table_=table_name, parametr=param, related=[], params=opt)
        except Exception as e:
            return return_error(e.message)
        return return_response(threads_array)
    else:
        return HttpResponse(status=400)