예제 #1
0
def list(request):
    try:
        parameters = request.GET.dict()
        validate_optional_parameters(parameters, ['since', 'limit', 'order'], [None, None, 'desc'])
        if 'forum' in parameters and 'thread' not in parameters:
            from API.requests import forum_requests

            posts = forum_requests.getPostsList(parameters['forum'], parameters['since'],
                                               parameters['order'], parameters['limit'], [])
        elif 'thread' in parameters and 'forum' not in parameters:
            from API.requests import thread_requests

            posts = thread_requests.getPostsList(parameters['thread'], parameters['since'],
                                                parameters['order'], parameters['limit'])
        else:
            raise Exception("Wrong required parameters")
        response_json = {
            'code': 0,
            'response': posts,
        }
    except Exception as e:
        response_json = {
            'code': 1,
            'response': str(e),
        }
    return HttpResponse(json.dumps(response_json, ensure_ascii=False), content_type='application/json')
예제 #2
0
def listPosts(request):
    try:
        parameters = request.GET.dict()
        validate_required_parameters(parameters, ['forum'])
        validate_optional_parameters(parameters, ['limit', 'order', 'since', 'related'], [None, 'desc', None, []])

        posts = forum_requests.getPostsList(parameters['forum'], parameters['since'], parameters['order'], parameters['limit'], parameters['related'])
        response_json = {
            'code': 0,
            'response': posts,
        }
    except Exception as e:
        response_json = {
            'code': 1,
            'response': str(e),
        }
    return HttpResponse(json.dumps(response_json, ensure_ascii=False), content_type='application/json')