Skip to content

Commit

Permalink
Fixed django#1756 -- hide unpublished events from side menus for staff
Browse files Browse the repository at this point in the history
  • Loading branch information
ontowhee committed Dec 11, 2024
1 parent 75f3fde commit ac1080d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
22 changes: 22 additions & 0 deletions blog/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,28 @@ def test_no_past_upcoming_events(self):
self.assertEqual(response.status_code, 200)
self.assertQuerySetEqual(response.context["events"], [])

def test_no_unpublished_future_events(self):
"""
Make sure there are no unpublished future events in the "upcoming events" sidebar
"""
# We need a published entry on the index page so that it doesn't return a 404
Entry.objects.create(pub_date=self.yesterday, is_active=True, slug="a")
Event.objects.create(
date=self.tomorrow,
pub_date=self.yesterday,
is_active=False,
headline="inactive",
)
Event.objects.create(
date=self.tomorrow,
pub_date=self.tomorrow,
is_active=True,
headline="future publish date",
)
response = self.client.get(reverse("weblog:index"))
self.assertEqual(response.status_code, 200)
self.assertQuerySetEqual(response.context["events"], [])


class SitemapTests(DateTimeMixin, TestCase):
def test_sitemap(self):
Expand Down
4 changes: 1 addition & 3 deletions blog/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ def get_queryset(self):
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)

events_queryset = Event.objects.future()
if not self.request.user.is_staff:
events_queryset = events_queryset.published()
events_queryset = Event.objects.future().published()

context["events"] = events_queryset[:3]

Expand Down

0 comments on commit ac1080d

Please sign in to comment.