Skip to content

Commit

Permalink
Merge pull request #169 from springload/feature/updates-redirects
Browse files Browse the repository at this point in the history
add redirect from updates to blog/news
  • Loading branch information
sarahframe authored Aug 20, 2024
2 parents 83f278b + 376950a commit 5936962
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
11 changes: 11 additions & 0 deletions cdhweb/blog/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
from typing import Any
from django.contrib.syndication.views import Feed
from django.utils.feedgenerator import Atom1Feed
from django.views.generic.detail import DetailView
from django.views.generic.base import RedirectView
from django.shortcuts import get_object_or_404

from cdhweb.blog.models import BlogPost

Expand Down Expand Up @@ -60,3 +64,10 @@ class AtomBlogPostFeed(RssBlogPostFeed):

feed_type = Atom1Feed
subtitle = RssBlogPostFeed.description

class BlogPostRedirectView(RedirectView):
pattern_name = "blog-detail"

def get_redirect_url(self, *args, **kwargs):
post = get_object_or_404(BlogPost, slug=kwargs["slug"])
return post.url
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='blog-detail'),
path("updates/<slug>/", BlogPostRedirectView.as_view(), name='blog-detail'),
]

if settings.DEBUG:
Expand Down

0 comments on commit 5936962

Please sign in to comment.