Changeset View
Changeset View
Standalone View
Standalone View
swh/web/browse/views/revision.py
# Copyright (C) 2017-2018 The Software Heritage developers | # Copyright (C) 2017-2018 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 hashlib | import hashlib | ||||
import json | import json | ||||
import textwrap | import textwrap | ||||
from django.http import HttpResponse | from django.http import HttpResponse | ||||
from django.shortcuts import render, redirect | 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 django.utils.safestring import mark_safe | from django.utils.safestring import mark_safe | ||||
from swh.model.identifiers import persistent_identifier | from swh.model.identifiers import persistent_identifier | ||||
from swh.web.common import service | from swh.web.common import service | ||||
from swh.web.common.utils import ( | from swh.web.common.utils import ( | ||||
reverse, format_utc_iso_date, gen_path_info, swh_object_icons | reverse, format_utc_iso_date, gen_path_info, swh_object_icons | ||||
▲ Show 20 Lines • Show All 241 Lines • ▼ Show 20 Lines | def revision_browse(request, sha1_git, extra_path=None): | ||||
""" | """ | ||||
Django view that produces an HTML display of a revision | Django view that produces an HTML display of a revision | ||||
identified by its id. | identified by its id. | ||||
The url that points to it is :http:get:`/browse/revision/(sha1_git)/`. | The url that points to it is :http:get:`/browse/revision/(sha1_git)/`. | ||||
""" | """ | ||||
try: | try: | ||||
revision = service.lookup_revision(sha1_git) | revision = service.lookup_revision(sha1_git) | ||||
# some readme files can reference assets reachable from the | |||||
# browsed directory, handle that special case in order to | |||||
# correctly displayed them | |||||
if extra_path: | |||||
dir_info = \ | |||||
service.lookup_directory_with_path(revision['directory'], | |||||
extra_path) | |||||
if dir_info and dir_info['type'] == 'file': | |||||
file_raw_url = reverse( | |||||
'browse-content-raw', | |||||
url_args={'query_string': dir_info['checksums']['sha1']}) | |||||
return redirect(file_raw_url) | |||||
origin_info = None | origin_info = None | ||||
snapshot_context = None | snapshot_context = None | ||||
origin_type = request.GET.get('origin_type', None) | origin_type = request.GET.get('origin_type', None) | ||||
origin_url = request.GET.get('origin_url', None) | origin_url = request.GET.get('origin_url', None) | ||||
if not origin_url: | if not origin_url: | ||||
origin_url = request.GET.get('origin', None) | origin_url = request.GET.get('origin', None) | ||||
timestamp = request.GET.get('timestamp', None) | timestamp = request.GET.get('timestamp', None) | ||||
visit_id = request.GET.get('visit_id', None) | visit_id = request.GET.get('visit_id', None) | ||||
▲ Show 20 Lines • Show All 259 Lines • Show Last 20 Lines |