Пример #1
0
def execute_endpoint(request, api_url, response_type="json"):
    endpoint = registry.get(api_url) or Endpoint.objects.get(url=api_url)

    if check_permission(request, endpoint) is not None:
        return HttpResponseForbidden()

    params = {}
    for key in request.GET.keys():
        value = unescape(urllib.unquote(request.GET[key]))
        key = unescape(urllib.unquote(key))

        if key.startswith("list:"):
            key = key[5:]
            if key.startswith("int:"):
                params[key[4:]] = tuple(
                    [int(i.strip()) for i in value.split(",") if i])
            else:
                params[key] = tuple(
                    [str(i.strip()) for i in value.split(",") if i])
                    
        else:
            if key.startswith("int:"):
                try:
                    params[key[4:]] = int(value)
                except ValueError:
                    continue
            else:
                params[key] = str(value.strip())
    
    json = endpoint.run(params=params)

    return render_response(request, response_type, json)
Пример #2
0
def execute_view(request, view_url):
    view = PrebuiltView.objects.select_related("endpoint").get(url=view_url)

    if check_permission(request, view) is not None:
        return HttpResponseForbidden()

    json = view.endpoint.run(params=view.load_params())

    return render_response(request, response_type, json)
Пример #3
0
def retrieve_endpoint_form(request, api_url, response_type="json"):
    endpoint = registry.get(api_url) or Endpoint.objects.get(url=api_url)

    if check_permission(request, endpoint) is not None:
        return HttpResponseForbidden()

    variables = set()
    for apiquery in endpoint.endpoint_queries.all().select_related():
        variables.update(apiquery.query.get_variables())

    return render_response(request, response_type, {'variables': variables})