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 copy import copy | from copy import copy | ||||
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 ( | from swh.model.identifiers import CONTENT, DIRECTORY, RELEASE, REVISION, SNAPSHOT, swhid | ||||
CONTENT, | from swh.model.model import Snapshot | ||||
DIRECTORY, | |||||
RELEASE, | |||||
REVISION, | |||||
SNAPSHOT, | |||||
snapshot_identifier, | |||||
swhid, | |||||
) | |||||
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_directory_link, | gen_directory_link, | ||||
gen_release_link, | gen_release_link, | ||||
gen_revision_link, | gen_revision_link, | ||||
gen_revision_log_link, | gen_revision_log_link, | ||||
Show All 20 Lines | |||||
from swh.web.common.utils import ( | from swh.web.common.utils import ( | ||||
format_utc_iso_date, | format_utc_iso_date, | ||||
gen_path_info, | gen_path_info, | ||||
reverse, | reverse, | ||||
swh_object_icons, | swh_object_icons, | ||||
) | ) | ||||
from swh.web.config import get_config | from swh.web.config import get_config | ||||
_empty_snapshot_id = snapshot_identifier({"branches": {}}) | _empty_snapshot_id = Snapshot(branches={}).id.hex() | ||||
def _get_branch(branches, branch_name, snapshot_id): | def _get_branch(branches, branch_name, snapshot_id): | ||||
""" | """ | ||||
Utility function to get a specific branch from a branches list. | Utility function to get a specific branch from a branches list. | ||||
Its purpose is to get the default HEAD branch as some software origin | Its purpose is to get the default HEAD branch as some software origin | ||||
(e.g those with svn type) does not have it. In that latter case, check | (e.g those with svn type) does not have it. In that latter case, check | ||||
if there is a master branch instead and returns it. | if there is a master branch instead and returns it. | ||||
▲ Show 20 Lines • Show All 1,389 Lines • Show Last 20 Lines |