Example #1
0
def detailForum(request):
    if request.method == "GET":
        requestData = getParam(request)
        requiredData = ["forum"]
        related = getRelated(requestData)
        try:
            tryParam(input=requestData, required=requiredData)
            forums = ForumsHelper.detailForumHelper(short_name=requestData["forum"], related=related)
        except Exception as e:
            return generateError(e.message)
        return getResponse(forums)
    else:
        return HttpResponse(status=400)
Example #2
0
def listUsersForum(request):
    if request.method == "GET":
        request_data = getParam(request)
        required_data = ["forum"]
        optional = getOptional(request=request_data, values=["limit", "order", "since_id"])
        try:
            tryParam(input=request_data, required=required_data)
            arrayUsers = ForumsHelper.listForumUsersHelper(request_data["forum"], optional)
        except Exception as e:
            return generateError(e.message)
        return getResponse(arrayUsers)
    else:
        return HttpResponse(status=400)
Example #3
0
def detailsPostHelper(id, option):
    post = postQueryHelper(id)
    if post is None:
        raise Exception("no post with id = "+id)

    if "user" in option:
        post["user"] = UsersHelper.detailsHelper(post["user"])
    if "forum" in option:
        post["forum"] = ForumsHelper.detailForumHelper(short_name=post["forum"], related=[])
    if "thread" in option:
        post["thread"] = ThreadsHelper.detailsThreadHelper(id=post["thread"], related=[])

    return post
Example #4
0
def createForum(request):
    if request.method == "POST":
        requiredData = ["name", "short_name", "user"]
        requestData = json.loads(request.body)
        try:
            tryParam(input=requestData, required=requiredData)
            forum = ForumsHelper.createForumHelper(name=requestData["name"], short_name=requestData["short_name"],
                                      user=requestData["user"])
        except Exception as e:
            print(e.message)
            return generateError(e.message)
        return getResponse(forum)
    else:
        return HttpResponse(status=400)
Example #5
0
def detailsThreadHelper(id, related):
    select = Select(
        'select date, forum, id, isClosed, isDeleted, message, slug, title, user, dislikes, likes, points, posts '
        'FROM Threads WHERE id = %s', (id, )
    )
    if len(select) == 0:
        raise Exception('No thread exists with id=' + str(id))
    select = threadFormat(select)

    if "user" in related:
        select["user"] = UsersHelper.detailsHelper(select["user"])
    if "forum" in related:
        select["forum"] = ForumsHelper.detailForumHelper(short_name=select["forum"], related=[])

    return select