Changeset View
Changeset View
Standalone View
Standalone View
swh/web/browse/views/content.py
# Copyright (C) 2017-2020 The Software Heritage developers | # Copyright (C) 2017-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 | ||||
import difflib | import difflib | ||||
from distutils.util import strtobool | from distutils.util import strtobool | ||||
import sentry_sdk | import sentry_sdk | ||||
from django.http import HttpResponse, JsonResponse | from django.http import HttpResponse, JsonResponse | ||||
from django.shortcuts import render | from django.shortcuts import render | ||||
from django.template.defaultfilters import filesizeformat | |||||
from swh.model.hashutil import hash_to_hex | from swh.model.hashutil import hash_to_hex | ||||
from swh.model.identifiers import CONTENT, DIRECTORY, RELEASE, REVISION, SNAPSHOT | from swh.model.identifiers import CONTENT, DIRECTORY, RELEASE, REVISION, SNAPSHOT | ||||
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 ( | ||||
content_display_max_size, | content_display_max_size, | ||||
gen_link, | gen_link, | ||||
▲ Show 20 Lines • Show All 288 Lines • ▼ Show 20 Lines | content_metadata = ContentMetadata( | ||||
object_id=content_checksums.get("sha1_git"), | object_id=content_checksums.get("sha1_git"), | ||||
sha1=content_checksums.get("sha1"), | sha1=content_checksums.get("sha1"), | ||||
sha1_git=content_checksums.get("sha1_git"), | sha1_git=content_checksums.get("sha1_git"), | ||||
sha256=content_checksums.get("sha256"), | sha256=content_checksums.get("sha256"), | ||||
blake2s256=content_checksums.get("blake2s256"), | blake2s256=content_checksums.get("blake2s256"), | ||||
content_url=content_url, | content_url=content_url, | ||||
mimetype=content_data.get("mimetype"), | mimetype=content_data.get("mimetype"), | ||||
encoding=content_data.get("encoding"), | encoding=content_data.get("encoding"), | ||||
size=filesizeformat(content_data.get("length", 0)), | size=content_data.get("length", 0), | ||||
language=content_data.get("language"), | language=content_data.get("language"), | ||||
root_directory=root_dir, | root_directory=root_dir, | ||||
path=f"/{path}" if path else None, | path=f"/{path}" if path else None, | ||||
filename=filename or "", | filename=filename or "", | ||||
directory=directory_id, | directory=directory_id, | ||||
revision=None, | revision=None, | ||||
release=None, | release=None, | ||||
snapshot=None, | snapshot=None, | ||||
▲ Show 20 Lines • Show All 69 Lines • Show Last 20 Lines |