Skip to content

Commit

Permalink
Merge pull request #2 from painless-security/jennifer/newest-blogs-in…
Browse files Browse the repository at this point in the history
…-sidebar

Always show most recent blog posts in sidebar. Fixes #28.
  • Loading branch information
meadmaker authored Apr 27, 2020
2 parents 27b9aa3 + c2f922f commit 14d5f3b
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 @@ -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')
Expand All @@ -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)
Expand All @@ -250,11 +252,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 @@ -265,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(),
Expand Down

0 comments on commit 14d5f3b

Please sign in to comment.