Exemplo n.º 1
0
def post_list(request):
    if request.method == "GET":
        request_data = return_GET_params(request)
        entity_attr = None
        try:
            entity_attr = request_data["forum"]
            entity = "forum"
        except KeyError:
            try:
                entity_attr = request_data["thread"]
                entity = "thread"
            except KeyError:
                return return_error("No thread or forum parameters in request")

        optional = return_optional(request=request_data,
                                   optional=["limit", "order", "since"])
        try:
            p_list = db_posts_funcs.post_list(entity=entity,
                                              entity_attr=entity_attr,
                                              related=[],
                                              params=optional)
        except Exception as e:
            return return_error(e.message)
        return return_response(p_list)
    else:
        return HttpResponse(status=400)
Exemplo n.º 2
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)