fix: ValueError on index page when no legislation

This commit is contained in:
stupidcomputer 2024-07-23 23:04:45 -05:00
parent 281473262a
commit 4931c8ac94
2 changed files with 6 additions and 2 deletions

View File

@ -16,7 +16,7 @@
{% endfor %}
</ul>
{% else %}
<p>No texts available</p>
<p>No texts available. If you're the admin, you need to add some texts with the admin interface.</p>
{% endif %}
<h2>About this instance</h2>

View File

@ -7,7 +7,11 @@ from random import sample
def index(request):
legislative_texts = list(LegislativeText.objects.all())
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,
}