Changeset View
Changeset View
Standalone View
Standalone View
swh/web/browse/views/utils/snapshot_context.py
# Copyright (C) 2018-2019 The Software Heritage developers | # Copyright (C) 2018-2019 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 | ||||
# Utility module implementing Django views for browsing the archive | # Utility module implementing Django views for browsing the archive | ||||
# in a snapshot context. | # in a snapshot context. | ||||
# Its purpose is to factorize code for the views reachable from the | # Its purpose is to factorize code for the views reachable from the | ||||
# /origin/.* and /snapshot/.* endpoints. | # /origin/.* and /snapshot/.* endpoints. | ||||
from django.shortcuts import render | 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 | ||||
import sentry_sdk | |||||
from swh.model.identifiers import snapshot_identifier | from swh.model.identifiers import snapshot_identifier | ||||
from swh.web.browse.utils import ( | from swh.web.browse.utils import ( | ||||
get_snapshot_context, get_directory_entries, gen_directory_link, | get_snapshot_context, get_directory_entries, gen_directory_link, | ||||
gen_revision_link, request_content, gen_content_link, | gen_revision_link, request_content, gen_content_link, | ||||
prepare_content_for_display, content_display_max_size, | prepare_content_for_display, content_display_max_size, | ||||
format_log_entries, gen_revision_log_link, gen_release_link, | format_log_entries, gen_revision_log_link, gen_release_link, | ||||
▲ Show 20 Lines • Show All 155 Lines • ▼ Show 20 Lines | def _process_snapshot_request(request, snapshot_id=None, | ||||
elif snapshot_total_size and release_name: | elif snapshot_total_size and release_name: | ||||
release = _get_release(releases, release_name, | release = _get_release(releases, release_name, | ||||
snapshot_context['snapshot_id']) | snapshot_context['snapshot_id']) | ||||
try: | try: | ||||
root_sha1_git = release['directory'] | root_sha1_git = release['directory'] | ||||
revision_id = release['target'] | revision_id = release['target'] | ||||
release_id = release['id'] | release_id = release['id'] | ||||
query_params['release'] = release_name | query_params['release'] = release_name | ||||
except Exception: | except Exception as exc: | ||||
sentry_sdk.capture_exception(exc) | |||||
_branch_not_found('release', release_name, snapshot_id, | _branch_not_found('release', release_name, snapshot_id, | ||||
snapshot_sizes, origin_info, timestamp, visit_id) | snapshot_sizes, origin_info, timestamp, visit_id) | ||||
elif snapshot_total_size: | elif snapshot_total_size: | ||||
branch_name = request.GET.get('branch', None) | branch_name = request.GET.get('branch', None) | ||||
if branch_name: | if branch_name: | ||||
query_params['branch'] = branch_name | query_params['branch'] = branch_name | ||||
branch = _get_branch(branches, branch_name or 'HEAD', | branch = _get_branch(branches, branch_name or 'HEAD', | ||||
snapshot_context['snapshot_id']) | snapshot_context['snapshot_id']) | ||||
try: | try: | ||||
branch_name = branch['name'] | branch_name = branch['name'] | ||||
revision_id = branch['revision'] | revision_id = branch['revision'] | ||||
root_sha1_git = branch['directory'] | root_sha1_git = branch['directory'] | ||||
except Exception: | except Exception as exc: | ||||
sentry_sdk.capture_exception(exc) | |||||
_branch_not_found('branch', branch_name, snapshot_id, | _branch_not_found('branch', branch_name, snapshot_id, | ||||
snapshot_sizes, origin_info, timestamp, visit_id) | snapshot_sizes, origin_info, timestamp, visit_id) | ||||
for b in branches: | for b in branches: | ||||
branch_url_args = dict(url_args) | branch_url_args = dict(url_args) | ||||
branch_query_params = dict(query_params) | branch_query_params = dict(query_params) | ||||
if 'release' in branch_query_params: | if 'release' in branch_query_params: | ||||
del branch_query_params['release'] | del branch_query_params['release'] | ||||
▲ Show 20 Lines • Show All 727 Lines • Show Last 20 Lines |