Changeset View
Changeset View
Standalone View
Standalone View
swh/web/browse/snapshot_context.py
# Copyright (C) 2018-2020 The Software Heritage developers | # Copyright (C) 2018-2021 The Software Heritage developers | ||||
anlambert: 2018-2021 | |||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU Affero General Public License version 3, or any later version | # License: GNU Affero General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
# Utility module for browsing the archive in a snapshot context. | # Utility module for browsing the archive in a snapshot context. | ||||
from collections import defaultdict | from collections import defaultdict | ||||
from typing import Any, Dict, List, Optional, Tuple | from typing import Any, Dict, List, Optional, Tuple | ||||
▲ Show 20 Lines • Show All 1,311 Lines • ▼ Show 20 Lines | return render( | ||||
"next_branches_url": next_branches_url, | "next_branches_url": next_branches_url, | ||||
"snapshot_context": snapshot_context, | "snapshot_context": snapshot_context, | ||||
"search_string": branch_name_include or "", | "search_string": branch_name_include or "", | ||||
}, | }, | ||||
) | ) | ||||
def browse_snapshot_releases( | def browse_snapshot_releases( | ||||
request, snapshot_id=None, origin_url=None, timestamp=None | request, | ||||
snapshot_id=None, | |||||
origin_url=None, | |||||
timestamp=None, | |||||
release_name_include=None, | |||||
): | ): | ||||
""" | """ | ||||
Django view implementation for browsing a list of releases in a snapshot | Django view implementation for browsing a list of releases in a snapshot | ||||
context. | context. | ||||
""" | """ | ||||
_check_origin_url(snapshot_id, origin_url) | _check_origin_url(snapshot_id, origin_url) | ||||
snapshot_context = get_snapshot_context( | snapshot_context = get_snapshot_context( | ||||
Show All 11 Lines | ): | ||||
url_args = snapshot_context["url_args"] | url_args = snapshot_context["url_args"] | ||||
query_params = snapshot_context["query_params"] | query_params = snapshot_context["query_params"] | ||||
snapshot = archive.lookup_snapshot( | snapshot = archive.lookup_snapshot( | ||||
snapshot_context["snapshot_id"], | snapshot_context["snapshot_id"], | ||||
rel_from, | rel_from, | ||||
PER_PAGE + 1, | PER_PAGE + 1, | ||||
target_types=["release", "alias"], | target_types=["release", "alias"], | ||||
branch_name_include_substring=release_name_include, | |||||
) | ) | ||||
displayed_releases = [] | |||||
if snapshot: | |||||
_, displayed_releases, _ = process_snapshot_branches(snapshot) | _, displayed_releases, _ = process_snapshot_branches(snapshot) | ||||
for release in displayed_releases: | for release in displayed_releases: | ||||
query_params_tgt = {"snapshot": snapshot_id} | query_params_tgt = {"snapshot": snapshot_id} | ||||
if origin_info: | if origin_info: | ||||
query_params_tgt["origin_url"] = origin_info["url"] | query_params_tgt["origin_url"] = origin_info["url"] | ||||
release_url = reverse( | release_url = reverse( | ||||
"browse-release", | "browse-release", | ||||
▲ Show 20 Lines • Show All 54 Lines • ▼ Show 20 Lines | if rel_bc: | ||||
prev_releases_url = reverse( | prev_releases_url = reverse( | ||||
browse_view_name, url_args=url_args, query_params=query_params_prev | browse_view_name, url_args=url_args, query_params=query_params_prev | ||||
) | ) | ||||
elif rel_from: | elif rel_from: | ||||
prev_releases_url = reverse( | prev_releases_url = reverse( | ||||
browse_view_name, url_args=url_args, query_params=query_params | browse_view_name, url_args=url_args, query_params=query_params | ||||
) | ) | ||||
if snapshot["next_branch"] is not None: | if snapshot and snapshot["next_branch"] is not None: | ||||
query_params_next = dict(query_params) | query_params_next = dict(query_params) | ||||
next_rel = displayed_releases[-1]["branch_name"] | next_rel = displayed_releases[-1]["branch_name"] | ||||
del displayed_releases[-1] | del displayed_releases[-1] | ||||
rel_bc.append(next_rel) | rel_bc.append(next_rel) | ||||
query_params_next["releases_breadcrumbs"] = ",".join(rel_bc) | query_params_next["releases_breadcrumbs"] = ",".join(rel_bc) | ||||
next_releases_url = reverse( | next_releases_url = reverse( | ||||
browse_view_name, url_args=url_args, query_params=query_params_next | browse_view_name, url_args=url_args, query_params=query_params_next | ||||
) | ) | ||||
Show All 15 Lines | return render( | ||||
"swh_object_metadata": {}, | "swh_object_metadata": {}, | ||||
"top_right_link": None, | "top_right_link": None, | ||||
"displayed_releases": displayed_releases, | "displayed_releases": displayed_releases, | ||||
"prev_releases_url": prev_releases_url, | "prev_releases_url": prev_releases_url, | ||||
"next_releases_url": next_releases_url, | "next_releases_url": next_releases_url, | ||||
"snapshot_context": snapshot_context, | "snapshot_context": snapshot_context, | ||||
"vault_cooking": None, | "vault_cooking": None, | ||||
"show_actions": False, | "show_actions": False, | ||||
"search_string": release_name_include or "", | |||||
}, | }, | ||||
) | ) |
2018-2021