Beispiel #1
0
def create():
    content = request.json
    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 json.dumps({"code": 0, "response": {
            'date': content["date"],
            'forum': content["forum"],
            'id': 1,
            'isClosed': False,
            'isDeleted': False,
            'message': content["message"],
            'slug': content["slug"],
            'title': content["title"],
            'user': content["user"]
        }
        })
    return json.dumps({"code": 0, "response": thread})
Beispiel #2
0
def create():
    content = request.json
    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:
    #     print e.message
    #     return json.dumps({"code": 0, "response": {
    #         'date': content["date"],
    #         'forum': content["forum"],
    #         'id': 1,
    #         'isApproved': True,
    #         'isDeleted': False,
    #         'isEdited': False,
    #         'isHighlighted': False,
    #         'isSpam': False,
    #         'message': content["message"],
    #         'thread': content["thread"],
    #         'user': 1
    #     }
    #     })
    print "ok"
    return json.dumps({"code": 0, "response": post})
Beispiel #3
0
def restore():
    content = request.json
    required_data = ["thread"]
    try:
        choose_required(data=content, required=required_data)
        thread = threads.remove_restore(thread_id=content["thread"], status=0)
    except Exception as e:
        return json.dumps({"code": 1, "response": (e.message)})
    return json.dumps({"code": 0, "response": thread})
Beispiel #4
0
def subscribe():
    content = request.json
    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 json.dumps({"code": 1, "response": (e.message)})
    return json.dumps({"code": 0, "response": subscription})
Beispiel #5
0
def vote():
    content = request.json
    required_data = ["post", "vote"]
    try:
        choose_required(data=content, required=required_data)
        post = posts.vote(vote_id=content["post"], vote_type=content["vote"])
    except Exception as e:
        return json.dumps({"code": 1, "response": (e.message)})
    return json.dumps({"code": 0, "response": post})
Beispiel #6
0
def details():
    request_data = get_json(request)
    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 json.dumps({"code": 1, "response": (e.message)})
    return json.dumps({"code": 0, "response": user_details})
Beispiel #7
0
def unfollow():
    request_data = request.json
    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 json.dumps({"code": 1, "response": (e.message)})
    return json.dumps({"code": 0, "response": following})
Beispiel #8
0
def update():
    request_data = request.json
    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 json.dumps({"code": 1, "response": (e.message)})
    return json.dumps({"code": 0, "response": user})
Beispiel #9
0
def open():
    content = request.json
    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 json.dumps({"code": 1, "response": (e.message)})
    return json.dumps({"code": 0, "response": thread})
Beispiel #10
0
def update():
    con = connect()
    content = request.json
    required_data = ["post", "message"]
    try:
        choose_required(data=content, required=required_data)
        post = posts.update(connect=con,update_id=content["post"], message=content["message"])
    except Exception as e:
        return json.dumps({"code": 1, "response": (e.message)})
    return json.dumps({"code": 0, "response": post})
Beispiel #11
0
def details():
    content = get_json(request)
    required_data = ["post"]
    related = related_exists(content)
    try:
        choose_required(data=content, required=required_data)
        post = posts.details(content["post"], related=related)
    except Exception as e:
        return json.dumps({"code": 1, "response": (e.message)})
    return json.dumps({"code": 0, "response": post})
Beispiel #12
0
def list_posts():
    request_data = get_json(request)
    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 json.dumps({"code": 1, "response": (e.message)})
    return json.dumps({"code": 0, "response": posts_l})
Beispiel #13
0
def list_following():
    request_data = get_json(request)
    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 json.dumps({"code": 1, "response": (e.message)})
    return json.dumps({"code": 0, "response": followings})
Beispiel #14
0
def vote():
    content = request.json
    required_data = ["thread", "vote"]
    try:
        choose_required(data=content, required=required_data)
        print("VOTE START")
        thread = threads.vote(id=content["thread"], vote=content["vote"])
    except Exception as e:
        return json.dumps({"code": 1, "response": (e.message)})
    return json.dumps({"code": 0, "response": thread})
Beispiel #15
0
def update():
    content = request.json
    required_data = ["thread", "slug", "message"]
    try:
        choose_required(data=content, required=required_data)
        thread = threads.update_thread(id=content["thread"], slug=content["slug"],
                                       message=content["message"])
    except Exception as e:
        return json.dumps({"code": 1, "response": (e.message)})
    return json.dumps({"code": 0, "response": thread})
Beispiel #16
0
def restore():
    content = request.json
    required_data = ["post"]
    try:
        choose_required(data=content, required=required_data)
        threads.inc_posts_count(content["post"])
        post = posts.remove_restore(post_id=content["post"], status=0)
    except Exception as e:
        return json.dumps({"code": 1, "response": (e.message)})
    return json.dumps({"code": 0, "response": post})
Beispiel #17
0
def list_users():
    content = get_json(request)
    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 json.dumps({"code": 1, "response": (e.message)})
    return json.dumps({"code": 0, "response": users_l})
Beispiel #18
0
def details():
    get_params = get_json(request)
    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 json.dumps({"code": 1, "response": (e.message)})
    return json.dumps({"code": 0, "response": forum})
Beispiel #19
0
def create():
    content = request.json
    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 json.dumps({"code": 1, "response": (e.message)})
    return json.dumps({"code": 0, "response": forum})
Beispiel #20
0
def remove():
    con = connect()
    content = get_json(request)
    required_data = ["post"]
    try:
        choose_required(data=content, required=required_data)
        post = posts.remove_restore(connect=con,post_id=content["post"], status=1)
        threads.dec_posts_count(con,content["post"])
    except Exception as e:
        return json.dumps({"code": 1, "response": (e.message)})
    return json.dumps({"code": 0, "response": post})
Beispiel #21
0
def list_posts():
    content = get_json(request)
    required_data = ["thread"]
    entity = "thread"
    optional = intersection(request=content, values=["limit", "order", "since", "sort"])
    # try:
    choose_required(data=content, required=required_data)
    p_list = posts.posts_list(entity=entity, params=optional, identifier=content["thread"], related=[])
    # except Exception as e:
    #     return json.dumps({"code": 1, "response": (e.message)})
    return json.dumps({"code": 0, "response": p_list})
Beispiel #22
0
def list_threads():
    content = get_json(request)
    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.thread_list(entity="forum", identifier=content["forum"],
                                         related=related, params=optional)
    except Exception as e:
        return json.dumps({"code": 1, "response": (e.message)})
    return json.dumps({"code": 0, "response": threads_l})
Beispiel #23
0
def details():
    content = get_json(request)
    required_data = ["thread"]
    related = related_exists(content)
    if 'thread' in related:
        return json.dumps({"code": 3, "response": "error"})
    try:
        choose_required(data=content, required=required_data)
        thread = threads.details(id=content["thread"], related=related)
    except Exception as e:
        return json.dumps({"code": 1, "response": (e.message)})
    return json.dumps({"code": 0, "response": thread})
Beispiel #24
0
def create():
    content = request.json
    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 json.dumps({"code": 1, "response": (e.message)})
    return json.dumps({"code": 0, "response": post})
Beispiel #25
0
def create():
    con = connect()
    request_data = request.json
    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(connect=con,email=request_data["email"], username=request_data["username"],
                               about=request_data["about"], name=request_data["name"], optional=optional)
    except Exception as e:
        if e.message == "5":
            return json.dumps({"code": 5, "response": (e.message)})
        return json.dumps({"code": 1, "response": (e.message)})
    return json.dumps({"code": 0, "response": user})
Beispiel #26
0
def details():
    content = get_json(request)
    required_data = ["thread"]
    related = related_exists(content)
    if 'thread' in related:
        return json.dumps({"code": 3, "response": "error"})
    try:
        choose_required(data=content, required=required_data)
        thread = threads.details(id=content["thread"], related=related)
        #print('thread is deleted')
        #print(thread['isDeleted'])
        #if thread['isDeleted'] == True:
        #    thread['posts'] = 0
        #    print(thread['posts'])
    except Exception as e:
        return json.dumps({"code": 1, "response": (e.message)})
    return json.dumps({"code": 0, "response": thread})
Beispiel #27
0
def list_posts():
    content = get_json(request)
    required_data = ["forum"]
    print content
    related = related_exists(content)
    print related

    optional = intersection(request=content, values=["limit", "order", "since"])
    #try:
    choose_required(data=content, required=required_data)
    posts_l = posts.posts_list(entity="forum", params=optional, identifier=content["forum"],
                                   related=related)
    #except Exception as e:
    #    print 'exeption /listPosts/'
    #    return json.dumps({"code": 1, "response": (e.message)})
    print ('correct /listPosts/')
    return json.dumps({"code": 0, "response": posts_l})