Changeset View
Changeset View
Standalone View
Standalone View
swh/web/utils/__init__.py
Show First 20 Lines • Show All 491 Lines • ▼ Show 20 Lines | def get_deposits_list(username: Optional[str] = None) -> List[Dict[str, Any]]: | ||||
deposits_data = _get_deposits_data() | deposits_data = _get_deposits_data() | ||||
return deposits_data["results"] | return deposits_data["results"] | ||||
_origin_visit_types_cache_timeout = 24 * 60 * 60 # 24 hours | _origin_visit_types_cache_timeout = 24 * 60 * 60 # 24 hours | ||||
def origin_visit_types(use_cache: bool = True) -> List[str]: | |||||
"""Return the exhaustive list of visit types for origins | |||||
ingested into the archive. | |||||
Args: | |||||
use_cache: if :const:`True`, store visit types in django | |||||
cache for 24 hours. | |||||
""" | |||||
@django_cache( | @django_cache( | ||||
timeout=_origin_visit_types_cache_timeout, | timeout=_origin_visit_types_cache_timeout, | ||||
catch_exception=True, | catch_exception=True, | ||||
exception_return_value=[], | exception_return_value=[], | ||||
invalidate_cache_pred=lambda val: not use_cache, | |||||
) | ) | ||||
def origin_visit_types() -> List[str]: | def _origin_visit_types_internal() -> List[str]: | ||||
"""Return the exhaustive list of visit types for origins | |||||
ingested into the archive. | |||||
""" | |||||
return sorted(search().visit_types_count().keys()) | return sorted(search().visit_types_count().keys()) | ||||
return _origin_visit_types_internal() | |||||
def redirect_to_new_route(request, new_route, permanent=True): | def redirect_to_new_route(request, new_route, permanent=True): | ||||
"""Redirect a request to another route with url args and query parameters | """Redirect a request to another route with url args and query parameters | ||||
eg: /origin/<url:url-val>/log?path=test can be redirected as | 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 | /log?url=<url-val>&path=test. This can be used to deprecate routes | ||||
""" | """ | ||||
request_path = resolve(request.path_info) | request_path = resolve(request.path_info) | ||||
args = {**request_path.kwargs, **request.GET.dict()} | args = {**request_path.kwargs, **request.GET.dict()} | ||||
return redirect( | return redirect( | ||||
reverse(new_route, query_params=args), | reverse(new_route, query_params=args), | ||||
permanent=permanent, | permanent=permanent, | ||||
) | ) |