Exemple #1
0
def abc(request, route):
    endpoints = RelativeEndpoint.objects.annotate(final_endpoint=Concat(
        'base_endpoint__endpoint', 'regex_endpoint')).all()
    endpoint = None
    for _route in endpoints:
        f = RegexPattern('^' + _route.final_endpoint + '$')
        if f.match(route) is not None:
            endpoint = _route
            break
    if endpoint is None:
        raise NotFound('Matching api endpoint not found')
    response = Response(endpoint.fields.all())
    return JsonResponse(response.create_response())
def abc(request, route):
    endpoints = RelativeEndpoint.objects.annotate(
        final_endpoint=Concat('base_endpoint__endpoint', 'regex_endpoint')).all()
    endpoint = None
    #   metas = RelativeEndpoint.objects.filter()
    url_params = {}
    for _route in endpoints:
        regex = _route_to_regex(_route.final_endpoint)
        f = RegexPattern(regex[0])
        is_match = f.match(route)
        if is_match is not None:
            url_params = is_match[2]
            endpoint = _route
            break
    if endpoint is None:
        raise NotFound('Matching api endpoint not found')
    if request.method != endpoint.method:
        raise NotAllowed("This method is not allowed")
    response = Response(endpoint.fields.all(), endpoint.meta_data, request.GET.get('pageNo', '1'), url_params, request.GET.dict())
    return JsonResponse(response.create_response())