Make legacy redirects permanent

This commit is contained in:
Jake Howard 2023-10-07 19:48:05 +01:00
parent d27504d46f
commit c94871008b
Signed by: jake
GPG key ID: 57AFB45680EDD477
2 changed files with 7 additions and 2 deletions

View file

@ -14,11 +14,11 @@ class PostsFeedViewTestCase(TestCase):
def test_redirects(self) -> None: def test_redirects(self) -> None:
response = self.client.get("/posts/index.xml") response = self.client.get("/posts/index.xml")
self.assertRedirects( 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): class AllPagesFeedViewTestCase(TestCase):
def test_redirects(self) -> None: def test_redirects(self) -> None:
response = self.client.get("/index.xml") response = self.client.get("/index.xml")
self.assertRedirects(response, reverse("feed")) self.assertRedirects(response, reverse("feed"), status_code=301)

View file

@ -8,6 +8,8 @@ from website.blog.models import BlogPostListPage, BlogPostTagListPage, BlogPostT
@method_decorator(cache_control(max_age=60 * 60), name="dispatch") @method_decorator(cache_control(max_age=60 * 60), name="dispatch")
class PostsFeedView(RedirectView): class PostsFeedView(RedirectView):
permanent = True
def get_redirect_url(self) -> str: def get_redirect_url(self) -> str:
post_list = get_object_or_404(BlogPostListPage) post_list = get_object_or_404(BlogPostListPage)
return post_list.url + post_list.reverse_subpage("feed") 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") @method_decorator(cache_control(max_age=60 * 60), name="dispatch")
class AllPagesFeedView(RedirectView): class AllPagesFeedView(RedirectView):
pattern_name = "feed" pattern_name = "feed"
permanent = True
@method_decorator(cache_control(max_age=60 * 60), name="dispatch") @method_decorator(cache_control(max_age=60 * 60), name="dispatch")
class TagView(RedirectView): class TagView(RedirectView):
permanent = True
def get_redirect_url(self, slug: str) -> str: def get_redirect_url(self, slug: str) -> str:
tag = get_object_or_404(BlogPostTagPage, slug=slug) tag = get_object_or_404(BlogPostTagPage, slug=slug)
return tag.get_url(request=self.request) return tag.get_url(request=self.request)