Skip to content

Commit 4cd81c3

Browse files
iampujanCopilotJacobCoffee
authored
Fix: Add permanent redirects for legacy sponsorship pages (Issue #2645) (#2944)
* Fix #2645: Add permanent redirects for legacy sponsorship pages * Fix #2645: Add permanent redirects for legacy sponsorship pages Address Copilot PR feedback: use url patterns and reverse for sponsors redirects * Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * Update pydotorg/urls.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Fix sponsorship-old redirect test to expect /psf/sponsorship/ --------- Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> Co-authored-by: Jacob Coffee <jacob@z7x.org>
1 parent 51055f1 commit 4cd81c3

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

‎pydotorg/tests/test_views.py‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,20 @@ def test_download_index(self):
3434
self.assertContains(response, "Browse Python 3.6.0 Documentation")
3535
self.assertContains(response, "https://docs.python.org/3/whatsnew/3.6.html")
3636
self.assertContains(response, "What's new in Python 3.6")
37+
38+
def test_legacy_sponsor_redirects(self):
39+
"""Test that old sponsorship pages correctly redirect to modern active ones."""
40+
redirect_cases = (
41+
("/psf/sponsorship-old/", "/psf/sponsorship/"),
42+
("/psf/forms/sponsor-application/", reverse("new_sponsorship_application")),
43+
)
44+
45+
for source_path, target_url in redirect_cases:
46+
with self.subTest(source_path=source_path, target_url=target_url):
47+
response = self.client.get(source_path)
48+
self.assertRedirects(
49+
response,
50+
target_url,
51+
status_code=301,
52+
fetch_redirect_response=False,
53+
)

‎pydotorg/urls.py‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from django.contrib import admin
66
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
77
from django.urls import include, path, re_path
8-
from django.views.generic.base import TemplateView
8+
from django.views.generic.base import RedirectView, TemplateView
99

1010
from apps.cms.views import custom_404
1111
from apps.downloads.views import ReleaseEditButton
@@ -35,6 +35,14 @@
3535
path("blogs/", include("apps.blogs.urls")),
3636
path("inner/", TemplateView.as_view(template_name="python/inner.html"), name="inner"),
3737
# other section landing pages
38+
path(
39+
"psf/sponsorship-old/",
40+
RedirectView.as_view(url="/psf/sponsorship/", permanent=True),
41+
),
42+
path(
43+
"psf/forms/sponsor-application/",
44+
RedirectView.as_view(pattern_name="new_sponsorship_application", permanent=True),
45+
),
3846
path("psf-landing/", TemplateView.as_view(template_name="psf/index.html"), name="psf-landing"),
3947
path("psf/sponsors/", TemplateView.as_view(template_name="psf/sponsors-list.html"), name="psf-sponsors"),
4048
path("docs-landing/", TemplateView.as_view(template_name="docs/index.html"), name="docs-landing"),

0 commit comments

Comments
 (0)