Changeset View
Changeset View
Standalone View
Standalone View
swh/web/api/views/origin.py
# Copyright (C) 2015-2019 The Software Heritage developers | # Copyright (C) 2015-2020 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU Affero General Public License version 3, or any later version | # License: GNU Affero General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
from distutils.util import strtobool | from distutils.util import strtobool | ||||
from functools import partial | from functools import partial | ||||
from swh.web.api.apidoc import api_doc, format_docstring | from swh.web.api.apidoc import api_doc, format_docstring | ||||
from swh.web.api.apiurls import api_route | from swh.web.api.apiurls import api_route | ||||
from swh.web.api.utils import enrich_origin, enrich_origin_visit | from swh.web.api.utils import ( | ||||
enrich_origin, | |||||
enrich_origin_search_result, | |||||
enrich_origin_visit, | |||||
) | |||||
from swh.web.api.views.utils import api_lookup | from swh.web.api.views.utils import api_lookup | ||||
from swh.web.common import archive | from swh.web.common import archive | ||||
from swh.web.common.exc import BadInputExc | from swh.web.common.exc import BadInputExc | ||||
from swh.web.common.origin_visits import get_origin_visits | from swh.web.common.origin_visits import get_origin_visits | ||||
from swh.web.common.utils import reverse | from swh.web.common.utils import reverse | ||||
DOC_RETURN_ORIGIN = """ | DOC_RETURN_ORIGIN = """ | ||||
:>json string origin_visits_url: link to in order to get information | :>json string origin_visits_url: link to in order to get information | ||||
▲ Show 20 Lines • Show All 168 Lines • ▼ Show 20 Lines | def api_origin_search(request, url_pattern): | ||||
with_visit = request.query_params.get("with_visit", "false") | with_visit = request.query_params.get("with_visit", "false") | ||||
(results, page_token) = api_lookup( | (results, page_token) = api_lookup( | ||||
archive.search_origin, | archive.search_origin, | ||||
url_pattern, | url_pattern, | ||||
limit, | limit, | ||||
bool(strtobool(with_visit)), | bool(strtobool(with_visit)), | ||||
page_token, | page_token, | ||||
enrich_fn=enrich_origin, | enrich_fn=enrich_origin_search_result, | ||||
request=request, | request=request, | ||||
) | ) | ||||
if page_token is not None: | if page_token is not None: | ||||
query_params = {} | query_params = {} | ||||
query_params["limit"] = limit | query_params["limit"] = limit | ||||
query_params["page_token"] = page_token | query_params["page_token"] = page_token | ||||
▲ Show 20 Lines • Show All 264 Lines • Show Last 20 Lines |