diff --git a/swh/web/browse/snapshot_context.py b/swh/web/browse/snapshot_context.py --- a/swh/web/browse/snapshot_context.py +++ b/swh/web/browse/snapshot_context.py @@ -35,12 +35,12 @@ gen_revision_log_link, gen_release_link, get_readme_to_display, - get_swh_persistent_ids, gen_snapshot_link, ) from swh.web.common import service, highlightjs from swh.web.common.exc import handle_view_exception, NotFoundExc, BadInputExc +from swh.web.common.identifiers import get_swh_persistent_ids from swh.web.common.origin_visits import get_origin_visit from swh.web.common.typing import ( OriginInfo, diff --git a/swh/web/browse/utils.py b/swh/web/browse/utils.py --- a/swh/web/browse/utils.py +++ b/swh/web/browse/utils.py @@ -17,11 +17,9 @@ from swh.web.common import highlightjs, service from swh.web.common.exc import http_status_code_message -from swh.web.common.identifiers import get_swh_persistent_id from swh.web.common.utils import ( reverse, format_utc_iso_date, - swh_object_icons, rst_to_html, ) from swh.web.config import get_config @@ -758,52 +756,3 @@ readme_html = "Readme bytes are not available" return readme_name, readme_url, readme_html - - -def get_swh_persistent_ids(swh_objects, snapshot_context=None): - """ - Returns a list of dict containing info related to persistent - identifiers of swh objects. - - Args: - swh_objects (list): a list of dict with the following keys: - - * type: swh object type - (content/directory/release/revision/snapshot) - * id: swh object id - - snapshot_context (dict): optional parameter describing the snapshot in - which the object has been found - - Returns: - list: a list of dict with the following keys: - * object_type: the swh object type - (content/directory/release/revision/snapshot) - * object_icon: the swh object icon to use in HTML views - * swh_id: the computed swh object persistent identifier - * swh_id_url: the url resolving the persistent identifier - * show_options: boolean indicating if the persistent id options - must be displayed in persistent ids HTML view - """ - swh_ids = [] - for swh_object in swh_objects: - if not swh_object["id"]: - continue - swh_id = get_swh_persistent_id(swh_object["type"], swh_object["id"]) - show_options = swh_object["type"] == "content" or ( - snapshot_context and snapshot_context["origin_info"] is not None - ) - - object_icon = swh_object_icons[swh_object["type"]] - - swh_ids.append( - { - "object_type": swh_object["type"], - "object_id": swh_object["id"], - "object_icon": object_icon, - "swh_id": swh_id, - "swh_id_url": reverse("browse-swh-id", url_args={"swh_id": swh_id}), - "show_options": show_options, - } - ) - return swh_ids diff --git a/swh/web/browse/views/content.py b/swh/web/browse/views/content.py --- a/swh/web/browse/views/content.py +++ b/swh/web/browse/views/content.py @@ -22,12 +22,12 @@ request_content, prepare_content_for_display, content_display_max_size, - get_swh_persistent_ids, gen_link, gen_directory_link, ) from swh.web.common import query, service, highlightjs from swh.web.common.exc import NotFoundExc, handle_view_exception +from swh.web.common.identifiers import get_swh_persistent_ids from swh.web.common.typing import ContentMetadata from swh.web.common.utils import reverse, gen_path_info, swh_object_icons diff --git a/swh/web/browse/views/directory.py b/swh/web/browse/views/directory.py --- a/swh/web/browse/views/directory.py +++ b/swh/web/browse/views/directory.py @@ -17,11 +17,11 @@ from swh.web.browse.utils import ( get_directory_entries, get_readme_to_display, - get_swh_persistent_ids, gen_link, ) from swh.web.common import service from swh.web.common.exc import handle_view_exception, NotFoundExc +from swh.web.common.identifiers import get_swh_persistent_ids from swh.web.common.typing import DirectoryMetadata from swh.web.common.utils import reverse, gen_path_info diff --git a/swh/web/browse/views/release.py b/swh/web/browse/views/release.py --- a/swh/web/browse/views/release.py +++ b/swh/web/browse/views/release.py @@ -13,7 +13,6 @@ gen_revision_link, gen_link, gen_snapshot_link, - get_swh_persistent_ids, gen_directory_link, gen_content_link, gen_release_link, @@ -21,6 +20,7 @@ ) from swh.web.common import service from swh.web.common.exc import NotFoundExc, handle_view_exception +from swh.web.common.identifiers import get_swh_persistent_ids from swh.web.common.typing import ReleaseMetadata from swh.web.common.utils import reverse, format_utc_iso_date diff --git a/swh/web/browse/views/revision.py b/swh/web/browse/views/revision.py --- a/swh/web/browse/views/revision.py +++ b/swh/web/browse/views/revision.py @@ -27,12 +27,12 @@ content_display_max_size, gen_snapshot_link, get_readme_to_display, - get_swh_persistent_ids, format_log_entries, gen_person_mail_link, ) from swh.web.common import service from swh.web.common.exc import NotFoundExc, handle_view_exception +from swh.web.common.identifiers import get_swh_persistent_ids from swh.web.common.typing import RevisionMetadata from swh.web.common.utils import ( reverse, diff --git a/swh/web/common/identifiers.py b/swh/web/common/identifiers.py --- a/swh/web/common/identifiers.py +++ b/swh/web/common/identifiers.py @@ -24,7 +24,7 @@ from swh.web.common.exc import BadInputExc from swh.web.common.typing import QueryParameters -from swh.web.common.utils import reverse +from swh.web.common.utils import swh_object_icons, reverse def get_swh_persistent_id( @@ -195,3 +195,52 @@ pids_by_type[obj_type].append(hash_to_bytes(obj_id)) return pids_by_type + + +def get_swh_persistent_ids(swh_objects, snapshot_context=None): + """ + Returns a list of dict containing info related to persistent + identifiers of swh objects. + + Args: + swh_objects (list): a list of dict with the following keys: + + * type: swh object type + (content/directory/release/revision/snapshot) + * id: swh object id + + snapshot_context (dict): optional parameter describing the snapshot in + which the object has been found + + Returns: + list: a list of dict with the following keys: + * object_type: the swh object type + (content/directory/release/revision/snapshot) + * object_icon: the swh object icon to use in HTML views + * swh_id: the computed swh object persistent identifier + * swh_id_url: the url resolving the persistent identifier + * show_options: boolean indicating if the persistent id options + must be displayed in persistent ids HTML view + """ + swh_ids = [] + for swh_object in swh_objects: + if not swh_object["id"]: + continue + swh_id = get_swh_persistent_id(swh_object["type"], swh_object["id"]) + show_options = swh_object["type"] == "content" or ( + snapshot_context and snapshot_context["origin_info"] is not None + ) + + object_icon = swh_object_icons[swh_object["type"]] + + swh_ids.append( + { + "object_type": swh_object["type"], + "object_id": swh_object["id"], + "object_icon": object_icon, + "swh_id": swh_id, + "swh_id_url": reverse("browse-swh-id", url_args={"swh_id": swh_id}), + "show_options": show_options, + } + ) + return swh_ids