Changeset View
Changeset View
Standalone View
Standalone View
swh/web/browse/views/origin.py
# Copyright (C) 2021 The Software Heritage developers | # Copyright (C) 2021 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, render | from django.shortcuts import redirect, render | ||||
from django.urls import resolve | |||||
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_content, | |||||
browse_snapshot_directory, | browse_snapshot_directory, | ||||
get_snapshot_context, | get_snapshot_context, | ||||
) | ) | ||||
from swh.web.common import archive | from swh.web.common import archive | ||||
from swh.web.common.exc import BadInputExc | from swh.web.common.exc import BadInputExc | ||||
from swh.web.common.origin_visits import get_origin_visits | from swh.web.common.origin_visits import get_origin_visits | ||||
from swh.web.common.utils import format_utc_iso_date, parse_iso8601_date_to_utc, reverse | from swh.web.common.utils import ( | ||||
format_utc_iso_date, | |||||
parse_iso8601_date_to_utc, | |||||
def redirect_to_new_route(request, new_route): | redirect_to_new_route, | ||||
request_path = resolve(request.path_info) | reverse, | ||||
# Send all the url_args and the request_args as query params | ) | ||||
# eg /origin/<url:url-val>/log?path=test | |||||
# will be send as /log?url=<url-val>&path=test | |||||
args = {**request_path.kwargs, **request.GET.dict()} | |||||
return redirect(reverse(new_route, query_params=args), permanent=True,) | |||||
@browse_route( | @browse_route( | ||||
r"origin/directory/", view_name="browse-origin-directory", | r"origin/directory/", view_name="browse-origin-directory", | ||||
) | ) | ||||
def origin_directory_browse(request): | def origin_directory_browse(request): | ||||
"""Django view for browsing the content of a directory associated | """Django view for browsing the content of a directory associated | ||||
to an origin for a given visit. | to an origin for a given visit. | ||||
Show All 32 Lines | return browse_snapshot_directory( | ||||
path=path, | path=path, | ||||
) | ) | ||||
@browse_route( | @browse_route( | ||||
r"origin/content/", view_name="browse-origin-content", | r"origin/content/", view_name="browse-origin-content", | ||||
) | ) | ||||
def origin_content_browse(request): | def origin_content_browse(request): | ||||
"""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 | |||||
associated to an origin for a given visit. | associated to an origin for a given visit. | ||||
The URL that points to it is :http:get:`/browse/origin/content/` | The URL that points to it is :http:get:`/browse/origin/content/` | ||||
""" | """ | ||||
return browse_snapshot_content( | return redirect_to_new_route(request, "browse-content") | ||||
request, | |||||
origin_url=request.GET.get("origin_url"), | |||||
snapshot_id=request.GET.get("snapshot"), | |||||
timestamp=request.GET.get("timestamp"), | |||||
path=request.GET.get("path"), | |||||
selected_language=request.GET.get("language"), | |||||
) | |||||
@browse_route( | @browse_route( | ||||
r"origin/(?P<origin_url>.+)/visit/(?P<timestamp>.+)/content/(?P<path>.+)/", | r"origin/(?P<origin_url>.+)/visit/(?P<timestamp>.+)/content/(?P<path>.+)/", | ||||
r"origin/(?P<origin_url>.+)/content/(?P<path>.+)/", | r"origin/(?P<origin_url>.+)/content/(?P<path>.+)/", | ||||
r"origin/(?P<origin_url>.+)/content/", | r"origin/(?P<origin_url>.+)/content/", | ||||
view_name="browse-origin-content-legacy", | view_name="browse-origin-content-legacy", | ||||
) | ) | ||||
def origin_content_browse_legacy(request, origin_url, path=None, timestamp=None): | def origin_content_browse_legacy(request, origin_url, path=None, timestamp=None): | ||||
"""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 | |||||
associated to an origin for a given visit. | associated to an origin for a given visit. | ||||
The URLs that point to it are | The URLs that point to it are | ||||
:http:get:`/browse/origin/(origin_url)/content/(path)/` and | :http:get:`/browse/origin/(origin_url)/content/(path)/` and | ||||
:http:get:`/browse/origin/(origin_url)/visit/(timestamp)/content/(path)/` | :http:get:`/browse/origin/(origin_url)/visit/(timestamp)/content/(path)/` | ||||
""" | """ | ||||
return browse_snapshot_content( | return redirect_to_new_route(request, "browse-content") | ||||
request, | |||||
origin_url=origin_url, | |||||
snapshot_id=request.GET.get("snapshot"), | |||||
timestamp=timestamp, | |||||
path=path, | |||||
selected_language=request.GET.get("language"), | |||||
) | |||||
@browse_route( | @browse_route( | ||||
r"origin/log/", view_name="browse-origin-log", | r"origin/log/", view_name="browse-origin-log", | ||||
) | ) | ||||
def origin_log_browse(request): | def origin_log_browse(request): | ||||
""" | """ | ||||
This route is deprecated; use http:get:`/browse/snapshot/log` instead | This route is deprecated; use http:get:`/browse/snapshot/log` instead | ||||
▲ Show 20 Lines • Show All 188 Lines • Show Last 20 Lines |