Changeset View
Changeset View
Standalone View
Standalone View
swh/web/common/identifiers.py
Show First 20 Lines • Show All 101 Lines • ▼ Show 20 Lines | ) -> ResolvedPersistentId: | ||||
swh_id_parsed = get_persistent_identifier(swh_id) | swh_id_parsed = get_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 | ||||
url_args = {} | url_args = {} | ||||
query_dict = QueryDict("", mutable=True) | query_dict = QueryDict("", mutable=True) | ||||
fragment = "" | fragment = "" | ||||
anchor_swhid_parsed = None | anchor_swhid_parsed = None | ||||
process_lines = object_type is CONTENT | |||||
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()): | ||||
query_dict[k] = query_params[k] | query_dict[k] = query_params[k] | ||||
if "origin" in swh_id_parsed.metadata: | if "origin" in swh_id_parsed.metadata: | ||||
query_dict["origin_url"] = swh_id_parsed.metadata["origin"] | query_dict["origin_url"] = swh_id_parsed.metadata["origin"] | ||||
▲ Show 20 Lines • Show All 66 Lines • ▼ Show 20 Lines | elif object_type in (CONTENT, DIRECTORY) and anchor_swhid_parsed: | ||||
# anchor revision, objects are browsed from its view | # anchor revision, objects are browsed from its view | ||||
object_type = REVISION | object_type = REVISION | ||||
object_id = anchor_swhid_parsed.object_id | object_id = anchor_swhid_parsed.object_id | ||||
elif object_type == DIRECTORY and anchor_swhid_parsed.object_type == DIRECTORY: | elif object_type == DIRECTORY and anchor_swhid_parsed.object_type == DIRECTORY: | ||||
# a directory is browsed from its root | # a directory is browsed from its root | ||||
object_id = anchor_swhid_parsed.object_id | object_id = anchor_swhid_parsed.object_id | ||||
if object_type == CONTENT: | if object_type == CONTENT: | ||||
query_string = "sha1_git:" + object_id | url_args["query_string"] = f"sha1_git:{object_id}" | ||||
if "lines" in swh_id_parsed.metadata: | |||||
lines = swh_id_parsed.metadata["lines"].split("-") | |||||
fragment += "#L" + lines[0] | |||||
if len(lines) > 1: | |||||
fragment += "-L" + lines[1] | |||||
url_args["query_string"] = query_string | |||||
elif object_type == DIRECTORY: | elif object_type == DIRECTORY: | ||||
url_args["sha1_git"] = object_id | url_args["sha1_git"] = object_id | ||||
elif object_type == RELEASE: | elif object_type == RELEASE: | ||||
url_args["sha1_git"] = object_id | url_args["sha1_git"] = object_id | ||||
elif object_type == REVISION: | elif object_type == REVISION: | ||||
url_args["sha1_git"] = object_id | url_args["sha1_git"] = object_id | ||||
elif object_type == SNAPSHOT: | elif object_type == SNAPSHOT: | ||||
url_args["snapshot_id"] = object_id | url_args["snapshot_id"] = object_id | ||||
elif object_type == ORIGIN: | elif object_type == ORIGIN: | ||||
raise BadInputExc( | raise BadInputExc( | ||||
( | ( | ||||
"Origin PIDs (Persistent Identifiers) are not " | "Origin PIDs (Persistent Identifiers) are not " | ||||
"publicly resolvable because they are for " | "publicly resolvable because they are for " | ||||
"internal usage only" | "internal usage only" | ||||
) | ) | ||||
) | ) | ||||
if "lines" in swh_id_parsed.metadata and process_lines: | |||||
lines = swh_id_parsed.metadata["lines"].split("-") | |||||
fragment += "#L" + lines[0] | |||||
if len(lines) > 1: | |||||
fragment += "-L" + lines[1] | |||||
if url_args: | if url_args: | ||||
browse_url = ( | browse_url = ( | ||||
reverse( | reverse( | ||||
f"browse-{object_type}", url_args=url_args, query_params=query_dict, | f"browse-{object_type}", url_args=url_args, query_params=query_dict, | ||||
) | ) | ||||
+ fragment | + fragment | ||||
) | ) | ||||
▲ Show 20 Lines • Show All 170 Lines • Show Last 20 Lines |