From 28a54e9d564ee63a0c45fb97cc879d9bb6abaf27 Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Fri, 6 Oct 2023 20:51:10 +0100 Subject: [PATCH] Add redirects for legacy tag URLs --- website/legacy/urls.py | 1 + website/legacy/views.py | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/website/legacy/urls.py b/website/legacy/urls.py index 6fa4786..c71904a 100644 --- a/website/legacy/urls.py +++ b/website/legacy/urls.py @@ -7,4 +7,5 @@ app_name = "legacy" urlpatterns = [ path("posts/index.xml", views.PostsFeedView.as_view()), path("index.xml", views.AllPagesFeedView.as_view()), + path("tags//", views.TagsView.as_view()), ] diff --git a/website/legacy/views.py b/website/legacy/views.py index 7ebcc82..b517583 100644 --- a/website/legacy/views.py +++ b/website/legacy/views.py @@ -3,7 +3,7 @@ from django.utils.decorators import method_decorator from django.views.decorators.cache import cache_control from django.views.generic import RedirectView -from website.blog.models import BlogPostListPage +from website.blog.models import BlogPostListPage, BlogPostTagListPage, BlogPostTagPage @method_decorator(cache_control(max_age=60 * 60), name="dispatch") @@ -16,3 +16,11 @@ class PostsFeedView(RedirectView): @method_decorator(cache_control(max_age=60 * 60), name="dispatch") class AllPagesFeedView(RedirectView): pattern_name = "feed" + + +@method_decorator(cache_control(max_age=60 * 60), name="dispatch") +class TagsView(RedirectView): + def get_redirect_url(self, slug: str) -> str: + get_object_or_404(BlogPostTagListPage) + tag = get_object_or_404(BlogPostTagPage, slug=slug) + return tag.get_url(request=self.request)