Add redirects for legacy tag URLs

This commit is contained in:
Jake Howard 2023-10-06 20:51:10 +01:00
parent 9bc200fe9f
commit 28a54e9d56
Signed by: jake
GPG key ID: 57AFB45680EDD477
2 changed files with 10 additions and 1 deletions

View file

@ -7,4 +7,5 @@ app_name = "legacy"
urlpatterns = [ urlpatterns = [
path("posts/index.xml", views.PostsFeedView.as_view()), path("posts/index.xml", views.PostsFeedView.as_view()),
path("index.xml", views.AllPagesFeedView.as_view()), path("index.xml", views.AllPagesFeedView.as_view()),
path("tags/<slug:slug>/", views.TagsView.as_view()),
] ]

View file

@ -3,7 +3,7 @@ from django.utils.decorators import method_decorator
from django.views.decorators.cache import cache_control from django.views.decorators.cache import cache_control
from django.views.generic import RedirectView 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") @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") @method_decorator(cache_control(max_age=60 * 60), name="dispatch")
class AllPagesFeedView(RedirectView): class AllPagesFeedView(RedirectView):
pattern_name = "feed" 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)