Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add redirect from updates to blog/news #169

Merged
merged 3 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions cdhweb/blog/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django.contrib.syndication.views import Feed
from django.utils.feedgenerator import Atom1Feed
from django.views.generic.detail import DetailView

from cdhweb.blog.models import BlogPost

Expand Down Expand Up @@ -60,3 +61,12 @@ class AtomBlogPostFeed(RssBlogPostFeed):

feed_type = Atom1Feed
subtitle = RssBlogPostFeed.description

class BlogPostRedirectView(DetailView):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might wanna use a RedirectView instead, then these two functions basically get smooshed into one


def get_object(self):
slug = self.kwargs["slug"]
return BlogPost.objects.live().filter(slug=slug).first()

def get(self, request, *args, **kwargs):
return self.get_object().serve(request)
3 changes: 3 additions & 0 deletions cdhweb/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from cdhweb.context_processors import favicon_path
from cdhweb.pages.views import OpenSearchDescriptionView, SiteSearchView
from cdhweb.events.views import EventIcalView
from cdhweb.blog.views import BlogPostRedirectView

admin.autodiscover()

Expand Down Expand Up @@ -69,6 +70,8 @@
# wagtail paths
path("cms/", include(wagtailadmin_urls)),
path("documents/", include(wagtaildocs_urls)),
re_path(r"updates/(?P<year>\d{4})/(?P<month>\d{2})/(?P<day>\d{2})/(?P<slug>[\w-]+)", BlogPostRedirectView.as_view(), name='updates-redirect-with-date'),
path("updates/<slug>/", BlogPostRedirectView.as_view(), name='updates-redirect'),
]

if settings.DEBUG:
Expand Down
Loading