Changeset View
Changeset View
Standalone View
Standalone View
swh/web/browse/views/release.py
# Copyright (C) 2017-2022 The Software Heritage developers | # Copyright (C) 2017-2022 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 | ||||
from typing import Optional | |||||
from django.http import HttpRequest, HttpResponse | |||||
from django.shortcuts import render | from django.shortcuts import render | ||||
from swh.model.swhids import ObjectType | from swh.model.swhids import ObjectType | ||||
from swh.web.browse.browseurls import browse_route | from swh.web.browse.browseurls import browse_route | ||||
from swh.web.browse.snapshot_context import get_snapshot_context | from swh.web.browse.snapshot_context import get_snapshot_context | ||||
from swh.web.browse.utils import ( | from swh.web.browse.utils import ( | ||||
gen_content_link, | gen_content_link, | ||||
gen_directory_link, | gen_directory_link, | ||||
gen_link, | gen_link, | ||||
gen_person_mail_link, | gen_person_mail_link, | ||||
gen_release_link, | gen_release_link, | ||||
gen_revision_link, | gen_revision_link, | ||||
) | ) | ||||
from swh.web.common import archive | from swh.web.common import archive | ||||
from swh.web.common.exc import NotFoundExc, sentry_capture_exception | from swh.web.common.exc import NotFoundExc, sentry_capture_exception | ||||
from swh.web.common.identifiers import get_swhids_info | from swh.web.common.identifiers import get_swhids_info | ||||
from swh.web.common.typing import ReleaseMetadata, SWHObjectInfo | from swh.web.common.typing import ReleaseMetadata, SnapshotContext, SWHObjectInfo | ||||
from swh.web.common.utils import format_utc_iso_date, reverse | from swh.web.common.utils import format_utc_iso_date, reverse | ||||
@browse_route( | @browse_route( | ||||
r"release/(?P<sha1_git>[0-9a-f]+)/", | r"release/(?P<sha1_git>[0-9a-f]+)/", | ||||
view_name="browse-release", | view_name="browse-release", | ||||
checksum_args=["sha1_git"], | checksum_args=["sha1_git"], | ||||
) | ) | ||||
def release_browse(request, sha1_git): | def release_browse(request: HttpRequest, sha1_git: str) -> HttpResponse: | ||||
""" | """ | ||||
Django view that produces an HTML display of a release | Django view that produces an HTML display of a release | ||||
identified by its id. | identified by its id. | ||||
The url that points to it is :http:get:`/browse/release/(sha1_git)/`. | The url that points to it is :http:get:`/browse/release/(sha1_git)/`. | ||||
""" | """ | ||||
release = archive.lookup_release(sha1_git) | release = archive.lookup_release(sha1_git) | ||||
snapshot_context = {} | snapshot_context: Optional[SnapshotContext] = None | ||||
origin_info = None | origin_info = None | ||||
snapshot_id = request.GET.get("snapshot_id") | snapshot_id = request.GET.get("snapshot_id") | ||||
if not snapshot_id: | if not snapshot_id: | ||||
snapshot_id = request.GET.get("snapshot") | snapshot_id = request.GET.get("snapshot") | ||||
origin_url = request.GET.get("origin_url") | origin_url = request.GET.get("origin_url") | ||||
if not origin_url: | if not origin_url: | ||||
origin_url = request.GET.get("origin") | origin_url = request.GET.get("origin") | ||||
timestamp = request.GET.get("timestamp") | timestamp = request.GET.get("timestamp") | ||||
Show All 23 Lines | if origin_url: | ||||
else: | else: | ||||
raise e | raise e | ||||
origin_info = snapshot_context["origin_info"] | origin_info = snapshot_context["origin_info"] | ||||
elif snapshot_id: | elif snapshot_id: | ||||
snapshot_context = get_snapshot_context( | snapshot_context = get_snapshot_context( | ||||
snapshot_id, release_name=release["name"] | snapshot_id, release_name=release["name"] | ||||
) | ) | ||||
if snapshot_context is not None: | |||||
snapshot_id = snapshot_context.get("snapshot_id", None) | snapshot_id = snapshot_context.get("snapshot_id", None) | ||||
release_metadata = ReleaseMetadata( | release_metadata = ReleaseMetadata( | ||||
object_type=ObjectType.RELEASE, | object_type=ObjectType.RELEASE, | ||||
object_id=sha1_git, | object_id=sha1_git, | ||||
release=sha1_git, | release=sha1_git, | ||||
author=release["author"]["fullname"] if release["author"] else "None", | author=release["author"]["fullname"] if release["author"] else "None", | ||||
author_url=gen_person_mail_link(release["author"]) | author_url=gen_person_mail_link(release["author"]) | ||||
if release["author"] | if release["author"] | ||||
▲ Show 20 Lines • Show All 156 Lines • Show Last 20 Lines |