fix: ValueError on index page when no legislation
This commit is contained in:
parent
281473262a
commit
4931c8ac94
|
@ -16,7 +16,7 @@
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
{% else %}
|
{% 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 %}
|
{% endif %}
|
||||||
|
|
||||||
<h2>About this instance</h2>
|
<h2>About this instance</h2>
|
||||||
|
|
|
@ -7,7 +7,11 @@ from random import sample
|
||||||
|
|
||||||
def index(request):
|
def index(request):
|
||||||
legislative_texts = list(LegislativeText.objects.all())
|
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 = {
|
context = {
|
||||||
"legislative_texts": legislative_texts,
|
"legislative_texts": legislative_texts,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue