From 4931c8ac94c8a5e3f050731d3691bcd220ef776c Mon Sep 17 00:00:00 2001 From: stupidcomputer Date: Tue, 23 Jul 2024 23:04:45 -0500 Subject: [PATCH] fix: ValueError on index page when no legislation --- franklincce/explorer/templates/explorer/index.html | 2 +- franklincce/explorer/views.py | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/franklincce/explorer/templates/explorer/index.html b/franklincce/explorer/templates/explorer/index.html index e9222f4..268679e 100644 --- a/franklincce/explorer/templates/explorer/index.html +++ b/franklincce/explorer/templates/explorer/index.html @@ -16,7 +16,7 @@ {% endfor %} {% else %} -

No texts available

+

No texts available. If you're the admin, you need to add some texts with the admin interface.

{% endif %}

About this instance

diff --git a/franklincce/explorer/views.py b/franklincce/explorer/views.py index 1c64100..58b3875 100644 --- a/franklincce/explorer/views.py +++ b/franklincce/explorer/views.py @@ -7,7 +7,11 @@ from random import sample def index(request): legislative_texts = list(LegislativeText.objects.all()) - legislative_texts = sample(legislative_texts, 5) + try: + legislative_texts = sample(legislative_texts, 5) + except ValueError: + # there's not enough texts, so just return nothing + legislative_texts = [] context = { "legislative_texts": legislative_texts, }