Changeset View
Changeset View
Standalone View
Standalone View
swh/web/common/utils.py
Show All 16 Lines | |||||
from iso8601 import ParseError, parse_date | from iso8601 import ParseError, parse_date | ||||
from pkg_resources import get_distribution | from pkg_resources import get_distribution | ||||
from prometheus_client.registry import CollectorRegistry | from prometheus_client.registry import CollectorRegistry | ||||
import requests | import requests | ||||
from requests.auth import HTTPBasicAuth | from requests.auth import HTTPBasicAuth | ||||
from django.core.cache import cache | from django.core.cache import cache | ||||
from django.http import HttpRequest, QueryDict | from django.http import HttpRequest, QueryDict | ||||
from django.shortcuts import redirect | |||||
from django.urls import resolve | |||||
from django.urls import reverse as django_reverse | from django.urls import reverse as django_reverse | ||||
from swh.web.auth.utils import ADMIN_LIST_DEPOSIT_PERMISSION | from swh.web.auth.utils import ADMIN_LIST_DEPOSIT_PERMISSION | ||||
from swh.web.common.exc import BadInputExc | from swh.web.common.exc import BadInputExc | ||||
from swh.web.common.typing import QueryParameters | from swh.web.common.typing import QueryParameters | ||||
from swh.web.config import get_config, search | from swh.web.config import get_config, search | ||||
SWH_WEB_METRICS_REGISTRY = CollectorRegistry(auto_describe=True) | SWH_WEB_METRICS_REGISTRY = CollectorRegistry(auto_describe=True) | ||||
▲ Show 20 Lines • Show All 377 Lines • ▼ Show 20 Lines | |||||
def origin_visit_types() -> List[str]: | def origin_visit_types() -> List[str]: | ||||
"""Return the exhaustive list of visit types for origins | """Return the exhaustive list of visit types for origins | ||||
ingested into the archive. | ingested into the archive. | ||||
""" | """ | ||||
try: | try: | ||||
return sorted(search().visit_types_count().keys()) | return sorted(search().visit_types_count().keys()) | ||||
except Exception: | except Exception: | ||||
return [] | return [] | ||||
def redirect_to_new_route(request, new_route, permanent=True): | |||||
"""Redirect a request to another route with url args and query parameters | |||||
eg: /origin/<url:url-val>/log?path=test can be redirected as | |||||
/log?url=<url-val>&path=test. This can be used to deprecate routes | |||||
""" | |||||
request_path = resolve(request.path_info) | |||||
anlambert: Too many lines in that docstring imho, you should make it more compact as you can use up to 88… | |||||
args = {**request_path.kwargs, **request.GET.dict()} | |||||
return redirect(reverse(new_route, query_params=args), permanent=permanent,) |
Too many lines in that docstring imho, you should make it more compact as you can use up to 88 columns per line.