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 render | ||||
| 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 get_snapshot_context | ||||
| browse_snapshot_directory, | |||||
| 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 ( | from swh.web.common.utils import ( | ||||
| format_utc_iso_date, | format_utc_iso_date, | ||||
| parse_iso8601_date_to_utc, | parse_iso8601_date_to_utc, | ||||
| redirect_to_new_route, | redirect_to_new_route, | ||||
| reverse, | reverse, | ||||
| ) | ) | ||||
| @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 | """ | ||||
| This route is deprecated; use http:get:`/browse/directory` instead | |||||
| Django view for browsing the content of a directory associated | |||||
| to an origin for a given visit. | to an origin for a given visit. | ||||
| The URL that points to it is :http:get:`/browse/origin/directory/` | The URL that points to it is :http:get:`/browse/origin/directory/` | ||||
| """ | """ | ||||
| return browse_snapshot_directory( | return redirect_to_new_route(request, "browse-directory") | ||||
| request, | |||||
| origin_url=request.GET.get("origin_url"), | |||||
| snapshot_id=request.GET.get("snapshot"), | |||||
| timestamp=request.GET.get("timestamp"), | |||||
| path=request.GET.get("path"), | |||||
| ) | |||||
| @browse_route( | @browse_route( | ||||
| r"origin/(?P<origin_url>.+)/visit/(?P<timestamp>.+)/directory/", | r"origin/(?P<origin_url>.+)/visit/(?P<timestamp>.+)/directory/", | ||||
| r"origin/(?P<origin_url>.+)/visit/(?P<timestamp>.+)/directory/(?P<path>.+)/", | r"origin/(?P<origin_url>.+)/visit/(?P<timestamp>.+)/directory/(?P<path>.+)/", | ||||
| r"origin/(?P<origin_url>.+)/directory/(?P<path>.+)/", | r"origin/(?P<origin_url>.+)/directory/(?P<path>.+)/", | ||||
| r"origin/(?P<origin_url>.+)/directory/", | r"origin/(?P<origin_url>.+)/directory/", | ||||
| view_name="browse-origin-directory-legacy", | view_name="browse-origin-directory-legacy", | ||||
| ) | ) | ||||
| def origin_directory_browse_legacy(request, origin_url, timestamp=None, path=None): | def origin_directory_browse_legacy(request, origin_url, timestamp=None, path=None): | ||||
| """Django view for browsing the content of a directory associated | """ | ||||
| This route is deprecated; use http:get:`/browse/directory` instead | |||||
| Django view for browsing the content of a directory associated | |||||
| to an origin for a given visit. | 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)/directory/[(path)/]` and | :http:get:`/browse/origin/(origin_url)/directory/[(path)/]` and | ||||
| :http:get:`/browse/origin/(origin_url)/visit/(timestamp)/directory/[(path)/]` | :http:get:`/browse/origin/(origin_url)/visit/(timestamp)/directory/[(path)/]` | ||||
| """ | """ | ||||
| return browse_snapshot_directory( | return redirect_to_new_route(request, "browse-directory") | ||||
| request, | |||||
| origin_url=origin_url, | |||||
| snapshot_id=request.GET.get("snapshot"), | |||||
| timestamp=timestamp, | |||||
| 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): | ||||
| """ | """ | ||||
| This route is deprecated; use http:get:`/browse/content` instead | This route is deprecated; use http:get:`/browse/content` instead | ||||
| ▲ Show 20 Lines • Show All 203 Lines • ▼ Show 20 Lines | def origin_visits_browse_legacy(request, origin_url): | ||||
| return _origin_visits_browse(request, origin_url) | return _origin_visits_browse(request, origin_url) | ||||
| @browse_route(r"origin/", view_name="browse-origin") | @browse_route(r"origin/", view_name="browse-origin") | ||||
| def origin_browse(request): | def origin_browse(request): | ||||
| """Django view that redirects to the display of the latest archived | """Django view that redirects to the display of the latest archived | ||||
| snapshot for a given software origin. | snapshot for a given software origin. | ||||
| """ | """ | ||||
| last_snapshot_url = reverse("browse-origin-directory", query_params=request.GET,) | return redirect_to_new_route(request, "browse-directory") | ||||
| return redirect(last_snapshot_url) | |||||
| @browse_route(r"origin/(?P<origin_url>.+)/", view_name="browse-origin-legacy") | @browse_route(r"origin/(?P<origin_url>.+)/", view_name="browse-origin-legacy") | ||||
| def origin_browse_legacy(request, origin_url): | def origin_browse_legacy(request, _): | ||||
| """Django view that redirects to the display of the latest archived | """ | ||||
| This route is deprecated; use http:get:`/browse/origin` instead | |||||
| Django view that redirects to the display of the latest archived | |||||
| snapshot for a given software origin. | snapshot for a given software origin. | ||||
| """ | """ | ||||
| last_snapshot_url = reverse( | return redirect_to_new_route(request, "browse-directory") | ||||
| "browse-origin-directory", | |||||
| query_params={"origin_url": origin_url, **request.GET}, | |||||
| ) | |||||
| return redirect(last_snapshot_url) | |||||