Skip to content

Commit

Permalink
Merge pull request #45 from painless-security/topic/28-newest-blogs
Browse files Browse the repository at this point in the history
Always show most recent blog posts in sidebar.
  • Loading branch information
rjsparks authored May 21, 2020
2 parents 7efa220 + 14d5f3b commit 598e8b0
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions ietf/blog/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,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')
Expand All @@ -228,6 +229,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)
Expand All @@ -253,11 +255,6 @@ def get_context(self, request, *args, **kwargs):
else:
filter_text = self.filter_topic.title

if self.coalesced_published_date():
siblings = siblings.filter(d__lt=self.coalesced_published_date() or datetime.now())[:5]
else:
siblings = siblings.none()

if filter_text:
if siblings:
filter_text = mark_safe("You have filtered by " + filter_text)
Expand All @@ -268,7 +265,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(),
Expand Down

0 comments on commit 598e8b0

Please sign in to comment.