diff --git a/ietf/blog/feeds.py b/ietf/blog/feeds.py index cbb07cdd..c2107ff8 100644 --- a/ietf/blog/feeds.py +++ b/ietf/blog/feeds.py @@ -37,11 +37,15 @@ def item_author_name(self, item): def item_pubdate(self, item): return item.date -class IABBlogFeed(BlogFeed): +class TopicBlogFeed(BlogFeed): + def __call__(self, request, *args, **kwargs): + self.topic = kwargs.get('topic') + return super().__call__(request, *args, **kwargs) + def items(self): return ( BlogPage.objects.live() - .filter(topics__topic__slug="iab") + .filter(topics__topic__slug=self.topic) .annotate(d=Coalesce("date_published", "first_published_at")) .order_by("-d") ) diff --git a/ietf/blog/tests.py b/ietf/blog/tests.py index 43a88b51..f3c7bb50 100644 --- a/ietf/blog/tests.py +++ b/ietf/blog/tests.py @@ -108,15 +108,28 @@ def test_blog_feed(self): self.assertIn(self.blog.url.encode(), r.content) self.assertIn(self.otherblog.url.encode(), r.content) - def test_iab_feed(self): - topic=Topic(title="iab", slug="iab") - topic.save() - iab_topic = BlogPageTopic(topic=topic, page=self.otherblog) + def test_topic_feed(self): + iab_topic = Topic(title="iab", slug="iab") iab_topic.save() - self.otherblog.topics = [iab_topic, ] + iab_bptopic = BlogPageTopic(topic=iab_topic, page=self.otherblog) + iab_bptopic.save() + self.otherblog.topics = [iab_bptopic, ] self.otherblog.save() + iesg_topic = Topic(title="iesg", slug="iesg") + iesg_topic.save() + iesg_bptopic = BlogPageTopic(topic=iesg_topic, page=self.otherblog) + iesg_bptopic.save() + self.nextblog.topics = [iesg_bptopic, ] + self.nextblog.save() r = self.client.get(path='/blog/iab/feed/') self.assertEqual(r.status_code, 200) - self.assertNotIn(self.blog.url.encode(), r.content) self.assertIn(self.otherblog.url.encode(), r.content) + self.assertNotIn(self.blog.url.encode(), r.content) + self.assertNotIn(self.nextblog.url.encode(), r.content) + + r = self.client.get(path='/blog/iesg/feed/') + self.assertEqual(r.status_code, 200) + self.assertIn(self.nextblog.url.encode(), r.content) + self.assertNotIn(self.blog.url.encode(), r.content) + self.assertNotIn(self.otherblog.url.encode(), r.content) diff --git a/ietf/urls.py b/ietf/urls.py index 0a04fcfc..1077214b 100644 --- a/ietf/urls.py +++ b/ietf/urls.py @@ -8,7 +8,7 @@ from wagtail.documents import urls as wagtaildocs_urls from ietf.bibliography import urls as bibliography_urls -from ietf.blog.feeds import BlogFeed, IABBlogFeed +from ietf.blog.feeds import BlogFeed, TopicBlogFeed from ietf.search.views import search from ietf.snippets import urls as snippet_urls @@ -21,7 +21,7 @@ url(r"^bibliography/", include(bibliography_urls)), url(r"^django-admin/", admin.site.urls), url(r"^blog/feed/$", BlogFeed(), name="blog_feed"), - url(r"^blog/iab/feed/$", IABBlogFeed(), name="iab_blog_feed"), + url(r"^blog/(?P.+)/feed/$", TopicBlogFeed(), name="blog_feed_with_topic"), url(r"^admin/", include(wagtailadmin_urls)), url(r"^documents/", include(wagtaildocs_urls)), url(r"^search/$", search, name="search"),