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-2020 The Software Heritage developers | ||||
# 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 | ||||
from django.core.cache import cache | from django.core.cache import cache | ||||
from django.shortcuts import render | from django.shortcuts import render | ||||
from django.template.defaultfilters import filesizeformat | from django.template.defaultfilters import filesizeformat | ||||
from django.utils.html import escape | from django.utils.html import escape | ||||
from swh.model.identifiers import CONTENT, DIRECTORY, RELEASE, REVISION, SNAPSHOT, swhid | from swh.model.hashutil import hash_to_bytes | ||||
from swh.model.identifiers import ( | |||||
CONTENT, | |||||
DIRECTORY, | |||||
RELEASE, | |||||
REVISION, | |||||
SNAPSHOT, | |||||
CoreSWHID, | |||||
ObjectType, | |||||
) | |||||
from swh.model.model import Snapshot | from swh.model.model import Snapshot | ||||
from swh.web.browse.utils import ( | from swh.web.browse.utils import ( | ||||
content_display_max_size, | content_display_max_size, | ||||
format_log_entries, | format_log_entries, | ||||
gen_content_link, | gen_content_link, | ||||
gen_release_link, | gen_release_link, | ||||
gen_revision_link, | gen_revision_link, | ||||
gen_revision_log_link, | gen_revision_log_link, | ||||
▲ Show 20 Lines • Show All 470 Lines • ▼ Show 20 Lines | ) -> SnapshotContext: | ||||
snapshot_sizes_cache_id = f"swh_snapshot_{snapshot_id}_sizes" | snapshot_sizes_cache_id = f"swh_snapshot_{snapshot_id}_sizes" | ||||
snapshot_sizes = cache.get(snapshot_sizes_cache_id) | snapshot_sizes = cache.get(snapshot_sizes_cache_id) | ||||
if snapshot_sizes is None: | if snapshot_sizes is None: | ||||
snapshot_sizes = archive.lookup_snapshot_sizes(snapshot_id) | snapshot_sizes = archive.lookup_snapshot_sizes(snapshot_id) | ||||
cache.set(snapshot_sizes_cache_id, snapshot_sizes) | cache.set(snapshot_sizes_cache_id, snapshot_sizes) | ||||
is_empty = (snapshot_sizes["release"] + snapshot_sizes["revision"]) == 0 | is_empty = (snapshot_sizes["release"] + snapshot_sizes["revision"]) == 0 | ||||
swh_snp_id = swhid("snapshot", snapshot_id) | swh_snp_id = str( | ||||
CoreSWHID(object_type=ObjectType.SNAPSHOT, object_id=hash_to_bytes(snapshot_id)) | |||||
) | |||||
if visit_info: | if visit_info: | ||||
timestamp = format_utc_iso_date(visit_info["date"]) | timestamp = format_utc_iso_date(visit_info["date"]) | ||||
if origin_info: | if origin_info: | ||||
browse_view_name = f"browse-origin-{browse_context}" | browse_view_name = f"browse-origin-{browse_context}" | ||||
else: | else: | ||||
browse_view_name = f"browse-snapshot-{browse_context}" | browse_view_name = f"browse-snapshot-{browse_context}" | ||||
▲ Show 20 Lines • Show All 930 Lines • Show Last 20 Lines |