Add legacy redirect app

This commit is contained in:
Jake Howard 2022-08-22 21:11:46 +01:00
parent bfa4755871
commit 922e259aaf
Signed by: jake
GPG Key ID: 57AFB45680EDD477
7 changed files with 47 additions and 0 deletions

View File

@ -0,0 +1,8 @@
from website.common.factories import BaseContentFactory
from . import models
class BlogPostListPageFactory(BaseContentFactory):
class Meta:
model = models.BlogPostListPage

View File

17
website/legacy/tests.py Normal file
View File

@ -0,0 +1,17 @@
from django.test import TestCase
from website.blog.factories import BlogPostListPageFactory
from website.home.models import HomePage
class PostsFeedViewTestCase(TestCase):
@classmethod
def setUpTestData(cls) -> None:
cls.home_page = HomePage.objects.get()
cls.page = BlogPostListPageFactory(parent=cls.home_page)
def test_redirects(self) -> None:
response = self.client.get("/posts/index.xml")
self.assertRedirects(
response, self.page.url + self.page.reverse_subpage("feed")
)

7
website/legacy/urls.py Normal file
View File

@ -0,0 +1,7 @@
from django.urls import path
from . import views
app_name = "legacy"
urlpatterns = [path("posts/index.xml", views.PostsFeedView.as_view())]

13
website/legacy/views.py Normal file
View File

@ -0,0 +1,13 @@
from django.shortcuts import get_object_or_404
from django.utils.decorators import method_decorator
from django.views.decorators.cache import cache_page
from django.views.generic import RedirectView
from website.blog.models import BlogPostListPage
@method_decorator(cache_page(60 * 60), name="dispatch")
class PostsFeedView(RedirectView):
def get_redirect_url(self) -> str:
post_list = get_object_or_404(BlogPostListPage.objects.live())
return post_list.url + post_list.reverse_subpage("feed")

View File

@ -35,6 +35,7 @@ INSTALLED_APPS = [
"website.spotify",
"website.utils",
"website.well_known",
"website.legacy",
"website.contrib.code_block",
"website.contrib.mermaid_block",
"website.contrib.unsplash",

View File

@ -25,6 +25,7 @@ urlpatterns = [
path("sitemap.xml", cache_page(60 * 60)(sitemap), name="sitemap"),
path("robots.txt", cache_page(60 * 60)(RobotsView.as_view()), name="robotstxt"),
path("404/", page_not_found, name="404"),
path("", include("website.legacy.urls")),
]