Changeset View
Changeset View
Standalone View
Standalone View
swh/web/common/utils.py
Show All 19 Lines | |||||
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.urls import reverse as django_reverse | from django.urls import reverse as django_reverse | ||||
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 ORIGIN_VISIT_TYPES, get_config | from swh.web.config import get_config, search | ||||
SWH_WEB_METRICS_REGISTRY = CollectorRegistry(auto_describe=True) | SWH_WEB_METRICS_REGISTRY = CollectorRegistry(auto_describe=True) | ||||
swh_object_icons = { | swh_object_icons = { | ||||
"alias": "mdi mdi-star", | "alias": "mdi mdi-star", | ||||
"branch": "mdi mdi-source-branch", | "branch": "mdi mdi-source-branch", | ||||
"branches": "mdi mdi-source-branch", | "branches": "mdi mdi-source-branch", | ||||
"content": "mdi mdi-file-document", | "content": "mdi mdi-file-document", | ||||
▲ Show 20 Lines • Show All 242 Lines • ▼ Show 20 Lines | return { | ||||
"swh_web_dev": "localhost" in site_base_url, | "swh_web_dev": "localhost" in site_base_url, | ||||
"swh_web_staging": any( | "swh_web_staging": any( | ||||
[ | [ | ||||
server_name in site_base_url | server_name in site_base_url | ||||
for server_name in config["staging_server_names"] | for server_name in config["staging_server_names"] | ||||
] | ] | ||||
), | ), | ||||
"swh_web_version": get_distribution("swh.web").version, | "swh_web_version": get_distribution("swh.web").version, | ||||
"visit_types": ORIGIN_VISIT_TYPES, | |||||
"iframe_mode": False, | "iframe_mode": False, | ||||
} | } | ||||
def resolve_branch_alias( | def resolve_branch_alias( | ||||
snapshot: Dict[str, Any], branch: Optional[Dict[str, Any]] | snapshot: Dict[str, Any], branch: Optional[Dict[str, Any]] | ||||
) -> Optional[Dict[str, Any]]: | ) -> Optional[Dict[str, Any]]: | ||||
""" | """ | ||||
▲ Show 20 Lines • Show All 88 Lines • ▼ Show 20 Lines | if not deposits_data or deposits_data["count"] != nb_deposits: | ||||
deposits_data = requests.get( | deposits_data = requests.get( | ||||
"%s?page_size=%s" % (deposits_list_url, nb_deposits), | "%s?page_size=%s" % (deposits_list_url, nb_deposits), | ||||
auth=deposits_list_auth, | auth=deposits_list_auth, | ||||
timeout=30, | timeout=30, | ||||
).json() | ).json() | ||||
cache.set("swh-deposit-list", deposits_data) | cache.set("swh-deposit-list", deposits_data) | ||||
return deposits_data["results"] | return deposits_data["results"] | ||||
def origin_visit_types() -> List[str]: | |||||
"""Return the exhaustive list of visit types for origins | |||||
ingested into the archive. | |||||
""" | |||||
try: | |||||
return sorted(search().visit_types_count().keys()) | |||||
except Exception: | |||||
return [] |