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 | ||||
import json | |||||
from distutils.util import strtobool | from distutils.util import strtobool | ||||
from django.http import HttpResponse | from django.http import HttpResponse, JsonResponse | ||||
from django.shortcuts import render | from django.shortcuts import render | ||||
from django.template.defaultfilters import filesizeformat | from django.template.defaultfilters import filesizeformat | ||||
import sentry_sdk | import sentry_sdk | ||||
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 | ||||
▲ Show 20 Lines • Show All 149 Lines • ▼ Show 20 Lines | else: | ||||
diff_lines = difflib.unified_diff(content_from_lines, content_to_lines) | diff_lines = difflib.unified_diff(content_from_lines, content_to_lines) | ||||
diff_str = "".join(list(diff_lines)[2:]) | diff_str = "".join(list(diff_lines)[2:]) | ||||
except Exception as exc: | except Exception as exc: | ||||
sentry_sdk.capture_exception(exc) | sentry_sdk.capture_exception(exc) | ||||
diff_str = str(exc) | diff_str = str(exc) | ||||
diff_data["diff_str"] = diff_str | diff_data["diff_str"] = diff_str | ||||
diff_data["language"] = language | diff_data["language"] = language | ||||
diff_data_json = json.dumps(diff_data, separators=(",", ": ")) | return JsonResponse(diff_data) | ||||
return HttpResponse(diff_data_json, content_type="application/json") | |||||
@browse_route( | @browse_route( | ||||
r"content/(?P<query_string>[0-9a-z_:]*[0-9a-f]+.)/", | r"content/(?P<query_string>[0-9a-z_:]*[0-9a-f]+.)/", | ||||
view_name="browse-content", | view_name="browse-content", | ||||
checksum_args=["query_string"], | checksum_args=["query_string"], | ||||
) | ) | ||||
def content_display(request, query_string): | def content_display(request, query_string): | ||||
▲ Show 20 Lines • Show All 225 Lines • Show Last 20 Lines |