def post_create():

    connection = dbConnector.connect()

    params = request.json

    optional = functions.get_optional(
        params,
        ["parent",
         "isApproved",
         "isHighlighted",
         "isEdited",
         "isSpam",
         "isDeleted"]
    )

    try:
        functions.check(
            params,
            ["date",
             "thread",
             "message",
             "user",
             "forum"]
        )

        response = post.create(connection, params["date"], params["thread"], params[
                               "message"], params["user"], params["forum"], optional)

    except Exception as e:
        connection.close()
        return json.dumps({"code": 3, "response": e.message})

    connection.close()
    return json.dumps({"code": 0, "response": response})
예제 #2
0
def post_list():
	con = dbConnector.connect()
	content = helpers.json_from_get(request)
	try:
		identifier = content["forum"]
		entity = "forum"
	except KeyError:
		try:
			identifier = content["thread"]
			entity = "thread"
		except Exception as e:
			con.close()
			return json.dumps({
				"code": 1,
				"response": (e.message)})

	optional = helpers.get_optional_params(request=content, values=["limit", "order", "since"])
	try:
		p_list = post.posts_list(con=con, entity=entity, params=optional, identifier=identifier, related=[])
	except Exception as e:
		con.close()
		return json.dumps({
			"code": 1,
			"response": (e.message)})
	con.close()
	return json.dumps({
		"code": 0,
		"response": p_list})
def forum_details():
    connection = dbConnector.connect()
    params = functions.get_json(request)
    try:
        functions.check(params, ["forum"])
        response = forum.details(
            connection, params["forum"], functions.get_related(params))
    except Exception, e:
        connection.close()
        return json.dumps({"code": 3, "response": e.message})
def post_vote():
    connection = dbConnector.connect()
    params = request.json
    try:
        functions.check(params, ["post", "vote"])
        response = post.vote(connection=connection, post=params["post"], vote=params["vote"])
    except Exception as e:
        connection.close()
        return json.dumps({"code": 1, "response": e.message})
    connection.close()
    return json.dumps({"code": 0, "response": response})
def forum_list_users():
    connection = dbConnector.connect()
    params = functions.get_json(request)
    optional = functions.get_optional(params, ["since_id", "limit", "order"])
    try:
        functions.check(params, ["forum"])
        response = forum.forum_listUsers(
            connection=connection, optional=optional, forum_shortname=params["forum"][0])
    except Exception, e:
        connection.close()
        return json.dumps({"code": 3, "response": e.message})
def forum_list_threads():
    connection = dbConnector.connect()
    params = functions.get_json(request)
    optional = functions.get_optional(params, ["since", "limit", "order"])
    related = functions.get_related(params)
    try:
        functions.check(params, ["forum"])
        response = thread.list(connection=connection, optional=optional,
                               required=params, related=related)
    except Exception, e:
        connection.close()
        return json.dumps({"code": 3, "response": e.message})
예제 #7
0
def user_updateProfile():
	con = dbConnector.connect()
	params = request.json

	try:
		helpers.check_params(params, ["about", "user", "name"])
		response = user.updateProfile(con=con, about=params["about"], user=params["user"], name=params["name"])
	except Exception as e:
		con.close()
		return json.dumps({"code": 1, "response": (e.message)})
	con.close()
	return json.dumps({"code": 0, "response": response})
def unsubscribe_thread():
    connection = dbConnector.connect()

    params = request.json

    try:
        functions.check(params, ["user", "thread"])
        response = thread.unsubscribe(
            connection=connection, user=params["user"], thread=params["thread"])
    except Exception, e:
        connection.close()
        return json.dumps({"code": 1, "response": e.message})
def post_restore():
    connection = dbConnector.connect()
    params = request.json
    try:
        functions.check(params, ["post"])
        response = post.restore_remove(
            connection=connection, post=params["post"], isDeleted=0)
        thread.inc_posts(connection, params["post"])
    except Exception as e:
        connection.close()
        return json.dumps({"code": 1, "response": e.message})
    connection.close()
    return json.dumps({"code": 0, "response": response})
def post_details():
    connection = dbConnector.connect()
    params = functions.get_json(request)
    required_data = ["post"]
    related = functions.get_related(params)
    try:
        functions.check(params, required_data)
        response = post.details(connection, params["post"], related)
    except Exception as e:
        connection.close()
        return json.dumps({"code": 1, "response": e.message})
    connection.close()
    return json.dumps({"code": 0, "response": response})
예제 #11
0
def user_unfollow():
	con = dbConnector.connect()
	params = request.json

	try:
		helpers.check_params(params, ["follower", "followee"])
		response = user.unfollow(con=con, follower_email=params["follower"], followee_email=params["followee"])
	except Exception as e:
		con.close()
		return json.dumps({"code": 1, "response": (e.message)})

	con.close()
	return json.dumps({"code": 0, "response": response})
def list_posts():
    connection = dbConnector.connect()
    params = functions.get_json(request)
    optional = functions.get_optional(
        request=params, values=["limit", "order", "since", "sort"])
    try:
        functions.check(params, ["thread"])
        response = post.posts_list(
            connection=connection, entity="thread", params=optional, identifier=params["thread"], related=[])
    except Exception as e:
        connection.close()
        return json.dumps({"code": 1, "response": e.message})
    connection.close()
    return json.dumps({"code": 0, "response": response})
예제 #13
0
def user_details():

	con = dbConnector.connect()
	params = helpers.json_from_get(request)

	try:
		helpers.check_params(params, ["user"])
		userr = user.details(con, params["user"])
	except Exception as e:
		con.close()
		return json.dumps({"code": 1, "response": (e.message)})
	
	con.close()
	return json.dumps({"code": 0, "response": userr})
def vote_thread():

    connection = dbConnector.connect()
    params = request.json

    try:
        functions.check(params, ["vote", "thread"])
        response = thread.vote(connection=connection, vote=params[
                               "vote"], thread=params["thread"])
    except Exception as e:
        connection.close()
        return json.dumps({"code": 1, "response": e.message})
    connection.close()
    return json.dumps({"code": 1, "response": response})
def user_details():

    connection = dbConnector.connect()
    params = functions.get_json(request)

    try:
        functions.check(params, ["user"])
        userr = user.details(connection, params["user"])
    except Exception as e:
        connection.close()
        return json.dumps({"code": 1, "response": e.message})

    connection.close()
    return json.dumps({"code": 0, "response": userr})
def update_thread():

    connection = dbConnector.connect()

    params = request.json

    try:
        functions.check(params, ["message", "slug", "thread"])
        response = thread.update(connection=connection, message=params["message"], slug=params[
                                 "slug"], thread=params["thread"])
    except Exception as e:
        connection.close()
        return json.dumps({"code": 1, "response": (e.message)})

    return json.dumps({"code": 0, "response": response})
def open_thread():

    connection = dbConnector.connect()

    params = request.json

    try:
        functions.check(params, ["thread"])
        response = thread.open_close(connection, params["thread"], isClosed=0)
    except Exception as e:
        connection.close()
        return json.dumps({"code": 1, "response": e.message})

    connection.close()
    return json.dumps({"code": 0, "response": response})
def remove_thread():

    connection = dbConnector.connect()

    params = request.json

    try:
        functions.check(params, ["thread"])
        response = thread.restore_remove(connection, params["thread"], isDeleted=1)
    except Exception as e:
        connection.close()
        return json.dumps({"code": 1, "response": e.message})

    connection.close()
    return json.dumps({"code": 0, "response": response})
예제 #19
0
def post_update():
	con = dbConnector.connect()
	params = request.json
	try:
		helpers.check_params(params, ["post", "message"])
		response = post.update(con=con, post=params["post"], message=params["message"])
	except Exception as e:
		con.close()
		return json.dumps({
			"code": 1,
			"response": (e.message)})
	con.close()
	return json.dumps({
		"code": 0,
		"response": response})
예제 #20
0
def user_listFollowers():

	con = dbConnector.connect()

	params = helpers.json_from_get(request)

	optional = helpers.get_optional_params(params, ["limit", "order", "since_id"])

	try:
		helpers.check_params(params, ["user"])
		response = user.listFollowers(con, params["user"], optional)
	except Exception as e:
		con.close()
		return json.dumps({"code": 1, "response": (e.message)})
	con.close()
	return json.dumps({"code": 0, "response": response})
def user_listFollowers():

    connection = dbConnector.connect()

    params = functions.get_json(request)

    optional = functions.get_optional(params, ["limit", "order", "since_id"])

    try:
        functions.check(params, ["user"])
        response = user.listFollowers(connection, params["user"], optional)
    except Exception as e:
        connection.close()
        return json.dumps({"code": 1, "response": e.message})
    connection.close()
    return json.dumps({"code": 0, "response": response})
예제 #22
0
def user_listPosts():

	con = dbConnector.connect()

	params = helpers.json_from_get(request)

	optional = helpers.get_optional_params(params, ["limit", "order", "since"])

	try:
		helpers.check_params(params, ["user"])
		response = post.posts_list(con=con, entity="user", params=optional, identifier=params["user"], related=[])
	except Exception as e:
		con.close()
		return json.dumps({"code": 1, "response": (e.message)})
	con.close()
	return json.dumps({"code": 0, "response": response})
def create_forum():
    connection = dbConnector.connect()
    params = request.json

    try:

        functions.check(params, ["name", "short_name", "user"])
        response = forum.create(connection, params["name"], params[
                                "short_name"], params["user"])

    except Exception as e:
        connection.close()
        return json.dumps({"code": 3, "response": e.message})

    connection.close()
    return json.dumps({"code": 0, "response": response})
예제 #24
0
def post_details():
	con = dbConnector.connect()
	params = helpers.json_from_get(request)
	required_data = ["post"]
	related = helpers.related_exists(params)
	try:
		helpers.check_params(params, required_data)
		response = post.details(con, params["post"], related)
	except Exception as e:
		con.close()
		return json.dumps({
			"code": 1,
			"response": (e.message)})
	con.close()
	return json.dumps({
		"code": 0,
		"response": response})
def forum_list_posts():
    connection = dbConnector.connect()
    params = functions.get_json(request)
    optional = functions.get_optional(
        params,
        ["since",
         "limit",
         "order"]
    )
    related = functions.get_related(params)
    try:
        functions.check(params, ["forum"])
        response = post.posts_list(connection, entity="forum", params=optional, identifier=params[
                                   "forum"], related=related)
    except Exception, e:
        connection.close()
        return json.dumps({"code": 3, "response": e.message})
예제 #26
0
def create_user():

	con = dbConnector.connect()
	params = request.json

	optional = helpers.get_optional_params(params, values=["isAnonymous"])

	try:
		helpers.check_params(params, ["username", "about", "name", "email"])
		userr = user.create(con, params["username"], params["about"], params["name"], params["email"], optional)
	except Exception as e:
		if e.message == "5":
			con.close();
			return json.dumps({"code": 5, "response": (e.message)})
		con.close()
		return json.dumps({"code": 1, "response": (e.message)})
	con.close()
	return json.dumps({"code": 0, "response": userr})
def list_thread():

    connection = dbConnector.connect()

    params = functions.get_json(request)

    optional = functions.get_optional(
        request=params, values=["since", "limit", "order"])

    try:
        response = thread.list(connection=connection, required=params,
                               optional=optional, related=[])
    except Exception as e:
        connection.close()
        return json.dumps({"code": 1, "response": e.message})

    connection.close()
    return json.dumps({"code": 0, "response": response})
예제 #28
0
def close_thread():
	con = dbConnector.connect()

	params = request.json

	try:
		helpers.check_params(params, ["thread"])
		response = thread.open_close(con, params["thread"], isClosed=1)
	except Exception as e:
		con.close()
		return ({
			"code": 1,
			"response": (e.message)})

	con.close()
	return json.dumps({
		"code": 0,
		"response": response})
def details_thread():

    connection = dbConnector.connect()
    params = functions.get_json(request)
    required_data = ["thread"]
    related = functions.get_related(params)

    if 'thread' in related:
        connection.close()
        return json.dumps({"code": 3, "response": "error"})
    try:
        functions.check(params, required_data)
        response = thread.details(connection, params["thread"], related)
    except Exception as e:
        connection.close()
        return json.dumps({"code": 1, "response": e.message})
    connection.close()
    return json.dumps({"code": 0, "response": response})
def create_thread():

    connection = dbConnector.connect()
    params = request.json

    optional = functions.get_optional(params, ["isDeleted"])

    try:
        functions.check(
            params, ["forum", "title", "isClosed", "user", "date", "message", "slug"])

        response = thread.create(connection, params["forum"], params["title"], params["isClosed"], params[
                                 "user"], params["date"], params["message"], params["slug"], optional)

    except Exception as e:
        connection.close()
        return json.dumps({"code": 3, "response": e.message})

    connection.close()
    return json.dumps({"code": 0, "response": response})