Changeset View
Changeset View
Standalone View
Standalone View
swh/web/common/utils.py
Show First 20 Lines • Show All 388 Lines • ▼ Show 20 Lines | def get_deposits_list(username: Optional[str] = None) -> List[Dict[str, Any]]: | ||||
deposits_list_url = _deposits_list_url( | deposits_list_url = _deposits_list_url( | ||||
deposits_list_base_url, page_size=1, username=username | deposits_list_base_url, page_size=1, username=username | ||||
) | ) | ||||
nb_deposits = requests.get( | nb_deposits = requests.get( | ||||
deposits_list_url, auth=deposits_list_auth, timeout=30 | deposits_list_url, auth=deposits_list_auth, timeout=30 | ||||
).json()["count"] | ).json()["count"] | ||||
deposits_data = cache.get(f"swh-deposit-list-{username}") | cache_key = f"swh-deposit-list-{username}" | ||||
deposits_data = cache.get(cache_key) | |||||
if not deposits_data or deposits_data["count"] != nb_deposits: | if not deposits_data or deposits_data["count"] != nb_deposits: | ||||
deposits_list_url = _deposits_list_url( | deposits_list_url = _deposits_list_url( | ||||
deposits_list_base_url, page_size=nb_deposits, username=username | deposits_list_base_url, page_size=nb_deposits, username=username | ||||
) | ) | ||||
deposits_data = requests.get( | deposits_data = requests.get( | ||||
deposits_list_url, auth=deposits_list_auth, timeout=30, | deposits_list_url, auth=deposits_list_auth, timeout=30, | ||||
).json() | ).json() | ||||
cache.set(f"swh-deposit-list-{username}", deposits_data) | cache.set(cache_key, deposits_data) | ||||
return deposits_data["results"] | return deposits_data["results"] | ||||
def get_deposit_raw_metadata(deposit_id: int) -> Optional[str]: | |||||
cache_key = f"swh-deposit-raw-metadata-{deposit_id}" | |||||
metadata = cache.get(cache_key) | |||||
if metadata is None: | |||||
config = get_config()["deposit"] | |||||
url = f"{config['private_api_url']}/{deposit_id}/meta" | |||||
metadata = requests.get(url).json()["metadata_raw"] | |||||
cache.set(cache_key, metadata) | |||||
return metadata | |||||
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 [] |