Changeset View
Changeset View
Standalone View
Standalone View
swh/web/browse/views/snapshot.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 | ||||
from django.shortcuts import redirect | from django.shortcuts import redirect | ||||
from swh.web.browse.browseurls import browse_route | from swh.web.browse.browseurls import browse_route | ||||
from swh.web.browse.snapshot_context import ( | from swh.web.browse.snapshot_context import ( | ||||
browse_snapshot_branches, | browse_snapshot_branches, | ||||
browse_snapshot_content, | |||||
browse_snapshot_directory, | browse_snapshot_directory, | ||||
browse_snapshot_log, | browse_snapshot_log, | ||||
browse_snapshot_releases, | browse_snapshot_releases, | ||||
get_snapshot_context, | get_snapshot_context, | ||||
) | ) | ||||
from swh.web.common.exc import BadInputExc | from swh.web.common.exc import BadInputExc | ||||
from swh.web.common.utils import reverse | from swh.web.common.utils import redirect_to_new_route, reverse | ||||
def get_snapshot_from_request(request): | def get_snapshot_from_request(request): | ||||
snapshot = request.GET.get("snapshot") | snapshot = request.GET.get("snapshot") | ||||
if snapshot: | if snapshot: | ||||
return snapshot | return snapshot | ||||
if request.GET.get("origin_url") is None: | if request.GET.get("origin_url") is None: | ||||
raise BadInputExc("An origin URL must be provided as a query parameter.") | raise BadInputExc("An origin URL must be provided as a query parameter.") | ||||
▲ Show 20 Lines • Show All 60 Lines • ▼ Show 20 Lines | |||||
@browse_route( | @browse_route( | ||||
r"snapshot/(?P<snapshot_id>[0-9a-f]+)/content/", | r"snapshot/(?P<snapshot_id>[0-9a-f]+)/content/", | ||||
view_name="browse-snapshot-content", | view_name="browse-snapshot-content", | ||||
checksum_args=["snapshot_id"], | checksum_args=["snapshot_id"], | ||||
) | ) | ||||
def snapshot_content_browse(request, snapshot_id): | def snapshot_content_browse(request, snapshot_id): | ||||
"""Django view that produces an HTML display of a content | """ | ||||
This route is deprecated; use http:get:`/browse/content` instead | |||||
Django view that produces an HTML display of a content | |||||
collected in a snapshot. | collected in a snapshot. | ||||
The url that points to it is :http:get:`/browse/snapshot/(snapshot_id)/content/` | The url that points to it is :http:get:`/browse/snapshot/(snapshot_id)/content/` | ||||
""" | """ | ||||
return browse_snapshot_content( | |||||
request, | return redirect_to_new_route(request, "browse-content") | ||||
snapshot_id=snapshot_id, | |||||
path=request.GET.get("path"), | |||||
selected_language=request.GET.get("language"), | |||||
) | |||||
@browse_route( | @browse_route( | ||||
r"snapshot/(?P<snapshot_id>[0-9a-f]+)/content/(?P<path>.+)/", | r"snapshot/(?P<snapshot_id>[0-9a-f]+)/content/(?P<path>.+)/", | ||||
view_name="browse-snapshot-content-legacy", | view_name="browse-snapshot-content-legacy", | ||||
checksum_args=["snapshot_id"], | checksum_args=["snapshot_id"], | ||||
) | ) | ||||
def snapshot_content_browse_legacy(request, snapshot_id, path): | def snapshot_content_browse_legacy(request, snapshot_id, path): | ||||
"""Django view that produces an HTML display of a content | """ | ||||
This route is deprecated; use http:get:`/browse/content` instead | |||||
Django view that produces an HTML display of a content | |||||
collected in a snapshot. | collected in a snapshot. | ||||
The url that points to it is | The url that points to it is | ||||
:http:get:`/browse/snapshot/(snapshot_id)/content/(path)/` | :http:get:`/browse/snapshot/(snapshot_id)/content/(path)/` | ||||
""" | """ | ||||
return browse_snapshot_content( | return redirect_to_new_route(request, "browse-content") | ||||
request, | |||||
snapshot_id=snapshot_id, | |||||
path=path, | |||||
selected_language=request.GET.get("language"), | |||||
) | |||||
@browse_route( | @browse_route( | ||||
r"snapshot/(?P<snapshot_id>[0-9a-f]+)/log/", | r"snapshot/(?P<snapshot_id>[0-9a-f]+)/log/", | ||||
r"snapshot/log/", | r"snapshot/log/", | ||||
view_name="browse-snapshot-log", | view_name="browse-snapshot-log", | ||||
checksum_args=["snapshot_id"], | checksum_args=["snapshot_id"], | ||||
) | ) | ||||
▲ Show 20 Lines • Show All 95 Lines • Show Last 20 Lines |