From a177c73736ff38309d3c3adb1ff231441f788a77 Mon Sep 17 00:00:00 2001 From: Jennifer Richards Date: Tue, 11 Feb 2020 16:48:38 -0500 Subject: [PATCH 1/3] Always show most recent blog posts in sidebar. Fixes #28. --- ietf/blog/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ietf/blog/models.py b/ietf/blog/models.py index 6044f35f..f08d641a 100644 --- a/ietf/blog/models.py +++ b/ietf/blog/models.py @@ -251,7 +251,7 @@ def get_context(self, request, *args, **kwargs): filter_text = self.filter_topic.title if self.coalesced_published_date(): - siblings = siblings.filter(d__lt=self.coalesced_published_date() or datetime.now())[:5] + siblings = siblings.filter(d__lt=datetime.now())[:5] else: siblings = siblings.none() From 0540b5c4c01b1a9467eb44f561b4e39f2142b353 Mon Sep 17 00:00:00 2001 From: Jennifer Richards Date: Fri, 6 Mar 2020 11:34:58 -0500 Subject: [PATCH 2/3] Remove unnecessary if statement --- ietf/blog/models.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/ietf/blog/models.py b/ietf/blog/models.py index f08d641a..e8260109 100644 --- a/ietf/blog/models.py +++ b/ietf/blog/models.py @@ -250,10 +250,7 @@ def get_context(self, request, *args, **kwargs): else: filter_text = self.filter_topic.title - if self.coalesced_published_date(): - siblings = siblings.filter(d__lt=datetime.now())[:5] - else: - siblings = siblings.none() + siblings = siblings.filter(d__lt=datetime.now())[:5] if filter_text: if siblings: From c2f922f360fa84b7810edaead36f7b997c41c8fc Mon Sep 17 00:00:00 2001 From: Jennifer Richards Date: Fri, 6 Mar 2020 13:05:48 -0500 Subject: [PATCH 3/3] Drop redundant siblings filter, add comments The BlogPage.siblings() method only returns live pages - no need to filter based on the current time. --- ietf/blog/models.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ietf/blog/models.py b/ietf/blog/models.py index e8260109..d4bdb361 100644 --- a/ietf/blog/models.py +++ b/ietf/blog/models.py @@ -215,6 +215,7 @@ def feed_text(self): @functional.cached_property def siblings(self): + """Published siblings that match filter_topic, most recent first""" qs = self.__class__.objects.live().sibling_of(self).annotate( d=Coalesce('date_published', 'first_published_at') ).order_by('-d') @@ -225,6 +226,7 @@ def siblings(self): def get_context(self, request, *args, **kwargs): context = super(BlogPage, self).get_context(request, *args, **kwargs) siblings = self.siblings + max_siblings_to_show = 5 query_string = "?" filter_text_builder = build_filter_text feed_settings = FeedSettings.for_site(request.site) @@ -250,8 +252,6 @@ def get_context(self, request, *args, **kwargs): else: filter_text = self.filter_topic.title - siblings = siblings.filter(d__lt=datetime.now())[:5] - if filter_text: if siblings: filter_text = mark_safe("You have filtered by " + filter_text) @@ -262,7 +262,7 @@ def get_context(self, request, *args, **kwargs): parent_url=self.get_parent().url, filter_text = filter_text, filter_topic = self.filter_topic, - siblings=siblings, + siblings=siblings[:max_siblings_to_show], topics=BlogPageTopic.objects.all().values_list( 'topic__pk', 'topic__title' ).distinct(),