Esempio n. 1
0
def details(request):
    if request.method == "GET":
        request_data = request.GET.dict()
        required_data = ["user"]
        try:
            choose_required(data=request_data, required=required_data)
            user_details = users.details(email=request_data["user"])
        except Exception as e:
            return HttpResponse(json.dumps({"code": 1, "response": (e.message)}), content_type='application/json')
        return HttpResponse(json.dumps({"code": 0, "response": user_details}), content_type='application/json')
    else:
        return HttpResponse(status=405)
Esempio n. 2
0
def unfollow(request):
    if request.method == "POST":
        request_data = json.loads(request.body)
        required_data = ["follower", "followee"]
        try:
            choose_required(data=request_data, required=required_data)
            following = followers.remove_follow(email1=request_data["follower"], email2=request_data["followee"])
        except Exception as e:
            return HttpResponse(json.dumps({"code": 1, "response": (e.message)}), content_type='application/json')
        return HttpResponse(json.dumps({"code": 0, "response": following}), content_type='application/json')
    else:
        return HttpResponse(status=405)
Esempio n. 3
0
def update(request):
    if request.method == "POST":
        request_data = json.loads(request.body)
        required_data = ["user", "name", "about"]
        try:
            choose_required(data=request_data, required=required_data)
            user = users.update_user(email=request_data["user"], name=request_data["name"], about=request_data["about"])
        except Exception as e:
            return HttpResponse(json.dumps({"code": 1, "response": (e.message)}), content_type='application/json')
        return HttpResponse(json.dumps({"code": 0, "response": user}), content_type='application/json')
    else:
        return HttpResponse(status=405)
Esempio n. 4
0
def update(request):
    if request.method == "POST":
        content = json.loads(request.body)
        required_data = ["post", "message"]
        try:
            choose_required(data=content, required=required_data)
            post = posts.update(update_id=content["post"], message=content["message"])
        except Exception as e:
            return HttpResponse(json.dumps({"code": 1, "response": (e.message)}), content_type='application/json')
        return HttpResponse(json.dumps({"code": 0, "response": post}), content_type='application/json')
    else:
        return HttpResponse(status=405)
Esempio n. 5
0
def open(request):
    if request.method == "POST":
        content = json.loads(request.body)
        required_data = ["thread"]
        try:
            choose_required(data=content, required=required_data)
            thread = threads.open_close_thread(id=content["thread"], isClosed=0)
        except Exception as e:
            return HttpResponse(json.dumps({"code": 1, "response": (e.message)}), content_type='application/json')
        return HttpResponse(json.dumps({"code": 0, "response": thread}), content_type='application/json')
    else:
        return HttpResponse(status=405)
Esempio n. 6
0
def subscribe(request):
    if request.method == "POST":
        content = json.loads(request.body)
        required_data = ["thread", "user"]
        try:
            choose_required(data=content, required=required_data)
            subscription = subscriptions.save_subscription(email=content["user"], thread_id=content["thread"])
        except Exception as e:
            return HttpResponse(json.dumps({"code": 1, "response": (e.message)}), content_type='application/json')
        return HttpResponse(json.dumps({"code": 0, "response": subscription}), content_type='application/json')
    else:
        return HttpResponse(status=405)
Esempio n. 7
0
def create(request):
    if request.method == "POST":
        content = json.loads(request.body)
        required_data = ["name", "short_name", "user"]
        try:
            choose_required(data=content, required=required_data)
            forum = forums.save_forum(name=content["name"], short_name=content["short_name"],
                                      user=content["user"])
        except Exception as e:
            return HttpResponse(json.dumps({"code": 1, "response": (e.message)}), content_type='application/json')
        return HttpResponse(json.dumps({"code": 0, "response": forum}), content_type='application/json')
    else:
        return HttpResponse(status=405)
Esempio n. 8
0
def list_users(request):
    if request.method == "GET":
        content = request.GET.dict()
        required_data = ["forum"]
        optional = intersection(request=content, values=["limit", "order", "since_id"])
        try:
            choose_required(data=content, required=required_data)
            users_l = forums.list_users(content["forum"], optional)
        except Exception as e:
            return HttpResponse(json.dumps({"code": 1, "response": (e.message)}), content_type='application/json')
        return HttpResponse(json.dumps({"code": 0, "response": users_l}), content_type='application/json')
    else:
        return HttpResponse(status=405)
Esempio n. 9
0
def details(request):
    if request.method == "GET":
        get_params = request.GET.dict()
        required_data = ["forum"]
        related = related_exists(get_params)
        try:
            choose_required(data=get_params, required=required_data)
            forum = forums.details(short_name=get_params["forum"], related=related)
        except Exception as e:
            return HttpResponse(json.dumps({"code": 1, "response": (e.message)}), content_type='application/json')
        return HttpResponse(json.dumps({"code": 0, "response": forum}), content_type='application/json')
    else:
        return HttpResponse(status=405)
Esempio n. 10
0
def list_following(request):
    if request.method == "GET":
        request_data = request.GET.dict()
        required_data = ["user"]
        followers_param = intersection(request=request_data, values=["limit", "order", "since_id"])
        try:
            choose_required(data=request_data, required=required_data)
            followings = followers.followers_list(email=request_data["user"], type="followee", params=followers_param)
        except Exception as e:
            return HttpResponse(json.dumps({"code": 1, "response": (e.message)}), content_type='application/json')
        return HttpResponse(json.dumps({"code": 0, "response": followings}), content_type='application/json')
    else:
        return HttpResponse(status=405)
Esempio n. 11
0
def list_posts(request):
    if request.method == "GET":
        request_data = request.GET.dict()
        required_data = ["user"]
        optional = intersection(request=request_data, values=["limit", "order", "since"])
        try:
            choose_required(data=request_data, required=required_data)
            posts_l = posts.posts_list(entity="user", params=optional, identifier=request_data["user"], related=[])
        except Exception as e:
            return HttpResponse(json.dumps({"code": 1, "response": (e.message)}), content_type='application/json')
        return HttpResponse(json.dumps({"code": 0, "response": posts_l}), content_type='application/json')
    else:
        return HttpResponse(status=405)
Esempio n. 12
0
def details(request):
    if request.method == "GET":
        content = request.GET.dict()
        required_data = ["thread"]
        related = related_exists(content)
        try:
            choose_required(data=content, required=required_data)
            thread = threads.details(id=content["thread"], related=related)
        except Exception as e:
            return HttpResponse(json.dumps({"code": 1, "response": (e.message)}), content_type='application/json')
        return HttpResponse(json.dumps({"code": 0, "response": thread}), content_type='application/json')
    else:
        return HttpResponse(status=405)
Esempio n. 13
0
def list_threads(request):
    if request.method == "GET":
        content = request.GET.dict()
        required_data = ["forum"]
        related = related_exists(content)
        optional = intersection(request=content, values=["limit", "order", "since"])
        try:
            choose_required(data=content, required=required_data)
            threads_l = threads.threads_list(entity="forum", identifier=content["forum"],
                                             related=related, params=optional)
        except Exception as e:
            return HttpResponse(json.dumps({"code": 1, "response": (e.message)}), content_type='application/json')
        return HttpResponse(json.dumps({"code": 0, "response": threads_l}), content_type='application/json')
    else:
        return HttpResponse(status=405)
Esempio n. 14
0
def create(request):
    if request.method == "POST":

        request_data = json.loads(request.body)
        required_data = ["email", "username", "name", "about"]
        optional = intersection(request=request_data, values=["isAnonymous"])
        try:
            choose_required(data=request_data, required=required_data)
            user = users.save_user(email=request_data["email"], username=request_data["username"],
                                   about=request_data["about"], name=request_data["name"], optional=optional)
        except Exception as e:
            return HttpResponse(json.dumps({"code": 1, "response": (e.message)}), content_type='application/json')
        return HttpResponse(json.dumps({"code": 0, "response": user}), content_type='application/json')
    else:
        return HttpResponse(status=405)
Esempio n. 15
0
def create(request):
    if request.method == "POST":

        content = json.loads(request.body)
        required_data = ["user", "forum", "thread", "message", "date"]
        optional_data = ["parent", "isApproved", "isHighlighted", "isEdited", "isSpam", "isDeleted"]
        optional = intersection(request=content, values=optional_data)
        try:
            choose_required(data=content, required=required_data)
            post = posts.create(date=content["date"], thread=content["thread"],
                                message=content["message"], user=content["user"],
                                forum=content["forum"], optional=optional)
        except Exception as e:
            return HttpResponse(json.dumps({"code": 1, "response": (e.message)}), content_type='application/json')
        return HttpResponse(json.dumps({"code": 0, "response": post}), content_type='application/json')
    else:
        return HttpResponse(status=405)
Esempio n. 16
0
def create(request):
    if request.method == "POST":

        content = json.loads(request.body)
        required_data = ["forum", "title", "isClosed", "user", "date", "message", "slug"]
        optional = intersection(request=content, values=["isDeleted"])
        try:
            choose_required(data=content, required=required_data)
            thread = threads.save_thread(forum=content["forum"], title=content["title"],
                                         isClosed=content["isClosed"],
                                         user=content["user"], date=content["date"],
                                         message=content["message"],
                                         slug=content["slug"], optional=optional)
        except Exception as e:
            return HttpResponse(json.dumps({"code": 1, "response": (e.message)}), content_type='application/json')
        return HttpResponse(json.dumps({"code": 0, "response": thread}), content_type='application/json')
    else:
        return HttpResponse(status=405)