Skip to content
This repository has been archived by the owner on Jun 1, 2022. It is now read-only.

Commit

Permalink
Redirect /admin/core/location/lxx/ to numeric ID, closes #698
Browse files Browse the repository at this point in the history
  • Loading branch information
simonw committed Jun 28, 2021
1 parent cdaaab0 commit 3aca574
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
8 changes: 8 additions & 0 deletions vaccinate/config/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,14 @@
path("admin_tools/", include("admin_tools.urls")),
path("admin/docs/", lambda r: redirect("/admin/docs/models/", permanent=False)),
path("admin/docs/", include("django.contrib.admindocs.urls")),
path(
"admin/core/location/l<str:partial_public_id>/change/",
tool_views.location_public_id_redirect,
),
path(
"admin/core/location/l<str:partial_public_id>/",
tool_views.location_public_id_redirect,
),
path(
# I renamed this model
"admin/core/callreport/",
Expand Down
19 changes: 19 additions & 0 deletions vaccinate/core/test_tool_views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import pytest
from django.utils import timezone
from reversion.models import Revision

Expand Down Expand Up @@ -301,3 +302,21 @@ def test_import_call_requests(admin_client, ten_locations):
(ten_locations[3].public_id, 4, False),
(ten_locations[4].public_id, 99, False),
]


@pytest.mark.parametrize(
"path",
(
"/admin/core/location/{public_id}",
"/admin/core/location/{public_id}/",
"/admin/core/location/{public_id}/change",
"/admin/core/location/{public_id}/change/",
),
)
def test_admin_core_location_public_id_redirect(admin_client, path, location):
response = admin_client.get(path.format(public_id=location.public_id), follow=True)
assert response.status_code == 200
# May have been two redirects if there was a missing trailing slash:
assert (
response.redirect_chain[-1][0] == f"/admin/core/location/{location.pk}/change/"
)
5 changes: 5 additions & 0 deletions vaccinate/core/tool_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,3 +269,8 @@ def bulk_delete_call_requests(request):
"message": message,
},
)


def location_public_id_redirect(request, partial_public_id):
location = get_object_or_404(Location, public_id=f"l{partial_public_id}")
return HttpResponseRedirect(f"/admin/core/location/{location.pk}/change/")

0 comments on commit 3aca574

Please sign in to comment.