From c94871008b7e27abe3a8e57ecf86aada4f12a270 Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Sat, 7 Oct 2023 19:48:05 +0100 Subject: [PATCH] Make legacy redirects permanent --- website/legacy/tests.py | 4 ++-- website/legacy/views.py | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/website/legacy/tests.py b/website/legacy/tests.py index fab474a..4d1ba7e 100644 --- a/website/legacy/tests.py +++ b/website/legacy/tests.py @@ -14,11 +14,11 @@ class PostsFeedViewTestCase(TestCase): def test_redirects(self) -> None: response = self.client.get("/posts/index.xml") self.assertRedirects( - response, self.page.url + self.page.reverse_subpage("feed") + response, self.page.url + self.page.reverse_subpage("feed"), status_code=301 ) class AllPagesFeedViewTestCase(TestCase): def test_redirects(self) -> None: response = self.client.get("/index.xml") - self.assertRedirects(response, reverse("feed")) + self.assertRedirects(response, reverse("feed"), status_code=301) diff --git a/website/legacy/views.py b/website/legacy/views.py index 02b1a87..6b5aeb0 100644 --- a/website/legacy/views.py +++ b/website/legacy/views.py @@ -8,6 +8,8 @@ from website.blog.models import BlogPostListPage, BlogPostTagListPage, BlogPostT @method_decorator(cache_control(max_age=60 * 60), name="dispatch") class PostsFeedView(RedirectView): + permanent = True + def get_redirect_url(self) -> str: post_list = get_object_or_404(BlogPostListPage) return post_list.url + post_list.reverse_subpage("feed") @@ -16,10 +18,13 @@ class PostsFeedView(RedirectView): @method_decorator(cache_control(max_age=60 * 60), name="dispatch") class AllPagesFeedView(RedirectView): pattern_name = "feed" + permanent = True @method_decorator(cache_control(max_age=60 * 60), name="dispatch") class TagView(RedirectView): + permanent = True + def get_redirect_url(self, slug: str) -> str: tag = get_object_or_404(BlogPostTagPage, slug=slug) return tag.get_url(request=self.request)