Changeset View
Changeset View
Standalone View
Standalone View
swh/web/common/utils.py
Show First 20 Lines • Show All 219 Lines • ▼ Show 20 Lines | def resolve_swh_persistent_id(swh_id, query_params=None): | ||||
Args: | Args: | ||||
swh_id (str): a Software Heritage persistent identifier | swh_id (str): a Software Heritage persistent identifier | ||||
query_params (django.http.QueryDict): optional dict filled with | query_params (django.http.QueryDict): optional dict filled with | ||||
query parameters to append to the browse url | query parameters to append to the browse url | ||||
Returns: | Returns: | ||||
dict: a dict with the following keys: | dict: a dict with the following keys: | ||||
* **swh_id_parsed (swh.model.identifiers.PersistentId)**: the parsed identifier | * **swh_id_parsed (swh.model.identifiers.PersistentId)**: | ||||
the parsed identifier | |||||
* **browse_url (str)**: the url for browsing the pointed object | * **browse_url (str)**: the url for browsing the pointed object | ||||
Raises: | Raises: | ||||
BadInputExc: if the provided identifier can not be parsed | BadInputExc: if the provided identifier can not be parsed | ||||
""" # noqa | """ | ||||
try: | try: | ||||
swh_id_parsed = parse_persistent_identifier(swh_id) | swh_id_parsed = parse_persistent_identifier(swh_id) | ||||
object_type = swh_id_parsed.object_type | object_type = swh_id_parsed.object_type | ||||
object_id = swh_id_parsed.object_id | object_id = swh_id_parsed.object_id | ||||
browse_url = None | browse_url = None | ||||
query_dict = QueryDict('', mutable=True) | query_dict = QueryDict('', mutable=True) | ||||
if query_params and len(query_params) > 0: | if query_params and len(query_params) > 0: | ||||
for k in sorted(query_params.keys()): | for k in sorted(query_params.keys()): | ||||
▲ Show 20 Lines • Show All 95 Lines • Show Last 20 Lines |