Add legacy redirect app
This commit is contained in:
parent
bfa4755871
commit
922e259aaf
7 changed files with 47 additions and 0 deletions
8
website/blog/factories.py
Normal file
8
website/blog/factories.py
Normal file
|
@ -0,0 +1,8 @@
|
|||
from website.common.factories import BaseContentFactory
|
||||
|
||||
from . import models
|
||||
|
||||
|
||||
class BlogPostListPageFactory(BaseContentFactory):
|
||||
class Meta:
|
||||
model = models.BlogPostListPage
|
0
website/legacy/__init__.py
Normal file
0
website/legacy/__init__.py
Normal file
17
website/legacy/tests.py
Normal file
17
website/legacy/tests.py
Normal 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
7
website/legacy/urls.py
Normal 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
13
website/legacy/views.py
Normal 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")
|
|
@ -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",
|
||||
|
|
|
@ -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")),
|
||||
]
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue