Skip to content

Commit

Permalink
feat: Change IAB blog feed to a generalized topic based feed
Browse files Browse the repository at this point in the history
  • Loading branch information
kesara committed Aug 14, 2023
1 parent dc89f69 commit 5eace2d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 10 deletions.
8 changes: 6 additions & 2 deletions ietf/blog/feeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
)
25 changes: 19 additions & 6 deletions ietf/blog/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
4 changes: 2 additions & 2 deletions ietf/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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<topic>.+)/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"),
Expand Down

0 comments on commit 5eace2d

Please sign in to comment.