Пример #1
0
def vote(request):
    if request.method == "POST":
        request_data = json.loads(request.body)
        required_data = ["thread", "vote"]
        try:
            params_are_right(request=request_data, required=required_data)
            thread = db_threads_funcs.thread_vote(thread_id=request_data["thread"], vote=request_data["vote"])
        except Exception as e:
            return return_error(e.message)
        return return_response(thread)
    else:
        return HttpResponse(status=400)
Пример #2
0
def details(request):
    if request.method == "GET":
        request_data = return_GET_params(request)
        required_data = ["thread"]
        related = return_related(request_data)
        try:
            params_are_right(request=request_data, required=required_data)
            thread = db_threads_funcs.thread_details(thread_id=request_data["thread"], related=related)
        except Exception as e:
            return return_error(e.message)
        return return_response(thread)
    else:
        return HttpResponse(status=400)
Пример #3
0
def details(request):
    if request.method == "GET":
        request_data = return_GET_params(request)
        required_data = ["user"]
        try:
            params_are_right(request=request_data,
                             required=required_data)
            user_details = db_users_func.user_details(email=request_data["user"])
        except Exception as e:
            return return_error(e.message)
        return return_response(user_details)
    else:
        return HttpResponse(status=400)
Пример #4
0
def unsubscribe(request):
    if request.method == "POST":
        request_data = json.loads(request.body)
        required_data = ["thread", "user"]
        try:
            params_are_right(request=request_data, required=required_data)
            subscription = db_subscriptions_funcs.thread_unsubscribe(
                sub_email=request_data["user"], thread_id=request_data["thread"]
            )
        except Exception as e:
            return return_error(e.message)
        return return_response(subscription)
    else:
        return HttpResponse(status=400)
Пример #5
0
def unfollow(request):
    if request.method == "POST":
        request_data = json.loads(request.body)
        required_data = ["follower", "followee"]
        try:
            params_are_right(request=request_data,
                             required=required_data)
            following = db_followers_funcs.user_unfollow(follower_email=request_data["follower"],
                                                         followee_email=request_data["followee"])
        except Exception as e:
            return return_error(e.message)
        return return_response(following)
    else:
        return HttpResponse(status=400)
Пример #6
0
def restore(request):
    if request.method == "POST":
        request_data = json.loads(request.body)
        required_data = ["post"]
        try:
            params_are_right(request=request_data,
                             required=required_data)
            post = db_posts_funcs.post_remove_or_restore(post_id=request_data["post"],
                                                         status=0)
        except Exception as e:
            return return_error(e.message)
        return return_response(post)
    else:
        return HttpResponse(status=400)
Пример #7
0
def list_followers(request):
    if request.method == "GET":
        request_data = return_GET_params(request)
        required_data = ["user"]
        followers_param = return_optional(request=request_data,
                                          optional=["limit", "order", "since_id"])
        try:
            params_are_right(request=request_data, required=required_data)
            follower_l = db_followers_funcs.user_list_followers_or_following(type_email=request_data["user"],
                                                                             type="follower", params=followers_param)
        except Exception as e:
            return return_error(e.message)
        return return_response(follower_l)
    else:
        return HttpResponse(status=400)
Пример #8
0
def update(request):
    if request.method == "POST":
        request_data = json.loads(request.body)
        required_data = ["user", "name", "about"]
        try:
            params_are_right(request=request_data,
                             required=required_data)
            user = db_users_func.user_update_profile(email=request_data["user"],
                                                     name=request_data["name"],
                                                     about=request_data["about"])
        except Exception as e:
            return return_error(e.message)
        return return_response(user)
    else:
        return HttpResponse(status=400)
Пример #9
0
def list_posts(request):
    if request.method == "GET":
        request_data = return_GET_params(request)
        required_data = ["thread"]
        entity = "thread"
        optional = return_optional(request=request_data, optional=["limit", "order", "since"])
        try:
            params_are_right(request=request_data, required=required_data)
            p_list = db_posts_funcs.post_list(
                entity=entity, entity_attr=request_data["thread"], related=[], params=optional
            )
        except Exception as e:
            return return_error(e.message)
        return return_response(p_list)
    else:
        return HttpResponse(status=400)
Пример #10
0
def create(request):
    if request.method == "POST":
        request_data = json.loads(request.body)
        required_data = ["email", "username", "name", "about"]
        optional = return_optional(request=request_data,
                                   optional=["isAnonymous"])
        try:
            params_are_right(request=request_data,
                             required=required_data)
            user = db_users_func.user_create(email=request_data["email"],
                                             username=request_data["username"],
                                             about=request_data["about"],
                                             name=request_data["name"],
                                             optional=optional)
        except Exception as e:
            return return_error(e.message)
        return return_response(user)
    else:
        return HttpResponse(status=400)
Пример #11
0
def create(request):
    if request.method == "POST":
        request_data = json.loads(request.body)
        required_data = ["user", "forum", "thread", "message", "date"]
        optional_data = ["parent", "isApproved", "isHighlighted", "isEdited", "isSpam", "isDeleted"]
        optional = return_optional(request=request_data,
                                   optional=optional_data)
        try:
            params_are_right(request=request_data,
                            required=required_data)
            post = db_posts_funcs.post_create(date=request_data["date"],
                                              thread=request_data["thread"],
                                              message=request_data["message"],
                                              user=request_data["user"],
                                              forum=request_data["forum"],
                                              optional=optional)
        except Exception as e:
            return return_error(e.message)
        return return_response(post)
    else:
        return HttpResponse(status=400)
Пример #12
0
def create(request):
    if request.method == "POST":
        request_data = json.loads(request.body)
        required_data = ["forum", "title", "isClosed", "user", "date", "message", "slug"]
        optional = return_optional(request=request_data, optional=["isDeleted"])
        try:
            params_are_right(request=request_data, required=required_data)
            thread = db_threads_funcs.thread_create(
                forum=request_data["forum"],
                title=request_data["title"],
                is_closed=request_data["isClosed"],
                user=request_data["user"],
                date=request_data["date"],
                message=request_data["message"],
                slug=request_data["slug"],
                optional=optional,
            )
        except Exception as e:
            return return_error(e.message)
        return return_response(thread)
    else:
        return HttpResponse(status=400)