Changeset View
Changeset View
Standalone View
Standalone View
swh/web/browse/views/directory.py
# Copyright (C) 2017-2019 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 os | import os | ||||
from django.http import HttpResponse | from django.http import HttpResponse | ||||
from django.shortcuts import render, redirect | from django.shortcuts import render, redirect | ||||
▲ Show 20 Lines • Show All 114 Lines • ▼ Show 20 Lines | def directory_browse(request, sha1_git, path=None): | ||||
vault_cooking = { | vault_cooking = { | ||||
'directory_context': True, | 'directory_context': True, | ||||
'directory_id': sha1_git, | 'directory_id': sha1_git, | ||||
'revision_context': False, | 'revision_context': False, | ||||
'revision_id': None | 'revision_id': None | ||||
} | } | ||||
swh_ids = get_swh_persistent_ids([{'type': 'directory', | swh_objects = [{'type': 'directory', 'id': sha1_git}] | ||||
'id': sha1_git}]) | |||||
swh_ids = get_swh_persistent_ids( | |||||
swh_objects=swh_objects, snapshot_context=snapshot_context) | |||||
heading = 'Directory - %s' % sha1_git | heading = 'Directory - %s' % sha1_git | ||||
if breadcrumbs: | if breadcrumbs: | ||||
dir_path = '/'.join([bc['name'] for bc in breadcrumbs]) + '/' | dir_path = '/'.join([bc['name'] for bc in breadcrumbs]) + '/' | ||||
heading += ' - %s' % dir_path | heading += ' - %s' % dir_path | ||||
return render(request, 'browse/directory.html', | return render(request, 'browse/directory.html', | ||||
{'heading': heading, | {'heading': heading, | ||||
'swh_object_id': swh_ids[0]['swh_id'], | 'swh_object_id': swh_ids[0]['swh_id'], | ||||
'swh_object_name': 'Directory', | 'swh_object_name': 'Directory', | ||||
'swh_object_metadata': dir_metadata, | 'swh_object_metadata': dir_metadata, | ||||
'dirs': dirs, | 'dirs': dirs, | ||||
'files': files, | 'files': files, | ||||
'breadcrumbs': breadcrumbs, | 'breadcrumbs': breadcrumbs, | ||||
'top_right_link': None, | 'top_right_link': None, | ||||
'readme_name': readme_name, | 'readme_name': readme_name, | ||||
'readme_url': readme_url, | 'readme_url': readme_url, | ||||
'readme_html': readme_html, | 'readme_html': readme_html, | ||||
'snapshot_context': snapshot_context, | 'snapshot_context': snapshot_context, | ||||
'vault_cooking': vault_cooking, | 'vault_cooking': vault_cooking, | ||||
'show_actions_menu': True, | 'show_actions_menu': True, | ||||
'swh_ids': swh_ids}) | 'swh_ids': swh_ids}) | ||||
@browse_route(r'directory/resolve/content-path/(?P<sha1_git>[0-9a-f]+)/(?P<path>.+)/', # noqa | @browse_route(r'directory/resolve/content-path/(?P<sha1_git>[0-9a-f]+)/(?P<path>.+)/', # noqa | ||||
view_name='browse-directory-resolve-content-path', | view_name='browse-directory-resolve-content-path', | ||||
checksum_args=['sha1_git']) | checksum_args=['sha1_git']) | ||||
def _directory_resolve_content_path(request, sha1_git, path): | def _directory_resolve_content_path(request, sha1_git, path): | ||||
""" | """ | ||||
Internal endpoint redirecting to data url for a specific file path | Internal endpoint redirecting to data url for a specific file path | ||||
relative to a root directory. | relative to a root directory. | ||||
""" | """ | ||||
try: | try: | ||||
Show All 11 Lines |