Skip to content

Commit

Permalink
urls: Fix redirects of pages with arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
Bjwebb committed Mar 5, 2025
1 parent 8414424 commit 6690e86
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 13 deletions.
2 changes: 1 addition & 1 deletion iati_dashboard/tests/test_page_speed.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
"publisher/zsl.html",
"codelist/2/[email protected]",
"element/[email protected]",
"org_type/.html",
"org_type/accountable_org.html",
"registration_agencies.html",
]

Expand Down
22 changes: 16 additions & 6 deletions iati_dashboard/ui/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ class OriginalDashboardRedirectTests(TestCase):
list the tests as they run.
"""

fixtures = ["publishers"]

def _url_and_view_helper(self, urls_and_views_to_check):
"""Checks that a set of URLs redirect to matching view functions"""

Expand Down Expand Up @@ -236,20 +238,28 @@ def test_exploringdata(self):
)

def test_slug_page_redirects(self):
"""Test pages with slugs redirect to the section page"""
"""Test pages with slugs redirect to their new locations"""

self.assertRedirects(
self.client.get(r"/publisher/zsl.html"), reverse("dash-headlines-publishers"), status_code=301
self.client.get(r"/publisher/zsl.html"),
reverse("dash-headlines-publisher-detail", args=["zsl"]),
status_code=301,
)
self.assertRedirects(self.client.get(r"/license/cc-by.html"), reverse("dash-licenses"), status_code=301)
self.assertRedirects(
self.client.get(r"/codelist/2/[email protected]"), reverse("dash-exploringdata-codelists"), status_code=301
self.client.get(r"/license/cc-by.html"), reverse("dash-licenses-detail", args=["cc-by"]), status_code=301
)
self.assertRedirects(
self.client.get(r"/codelist/2/[email protected]"),
reverse("dash-exploringdata-codelists-detail", args=["2", "budget_@type"]),
status_code=301,
)
self.assertRedirects(
self.client.get(r"/element/[email protected]"),
reverse("dash-exploringdata-elements"),
reverse("dash-exploringdata-elements-detail", args=["iati-activity_activity-date_@iso-date"]),
status_code=301,
)
self.assertRedirects(
self.client.get(r"/org_type/funding_org.html"), reverse("dash-exploringdata-orgids"), status_code=301
self.client.get(r"/org_type/funding_org.html"),
reverse("dash-exploringdata-orgtypes-detail", args=["funding_org"]),
status_code=301,
)
17 changes: 11 additions & 6 deletions iati_dashboard/ui/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,18 +188,23 @@
path("org_ids.html", RedirectView.as_view(pattern_name="dash-exploringdata-orgids", permanent=True)),
path("faq.html", RedirectView.as_view(pattern_name="dash-faq", permanent=True)),
path("licenses.html", RedirectView.as_view(pattern_name="dash-licenses", permanent=True)),
re_path(r"license\/\S*.html", RedirectView.as_view(pattern_name="dash-licenses", permanent=True)),
re_path(r"license\/(\S*).html", RedirectView.as_view(pattern_name="dash-licenses-detail", permanent=True)),
re_path(
r"publisher\/\S*.html", RedirectView.as_view(pattern_name="dash-headlines-publishers", permanent=True)
r"publisher\/(\S*).html",
RedirectView.as_view(pattern_name="dash-headlines-publisher-detail", permanent=True),
),
re_path(
r"codelist\/\d\/\S*.html",
RedirectView.as_view(pattern_name="dash-exploringdata-codelists", permanent=True),
r"codelist\/(\d)\/(\S*).html",
RedirectView.as_view(pattern_name="dash-exploringdata-codelists-detail", permanent=True),
),
re_path(
r"element\/\S*.html", RedirectView.as_view(pattern_name="dash-exploringdata-elements", permanent=True)
r"element\/(\S*).html",
RedirectView.as_view(pattern_name="dash-exploringdata-elements-detail", permanent=True),
),
re_path(
r"org_type\/(\S*).html",
RedirectView.as_view(pattern_name="dash-exploringdata-orgtypes-detail", permanent=True),
),
re_path(r"org_type\/\S*.html", RedirectView.as_view(pattern_name="dash-exploringdata-orgids", permanent=True)),
]
+ static("generated", document_root="out")
+ static("stats", document_root="stats-calculated")
Expand Down

0 comments on commit 6690e86

Please sign in to comment.