Commit 28f55629 authored by Jamesie Pic's avatar Jamesie Pic

Fix home on empty database

parent cc400d9c
......@@ -79,7 +79,11 @@
<div class="col-md-4 todays-mep">
<h2>{% trans "Today's Representative" %}</h2>
{% if todays_mep %}
{% include "representatives/_representative_card.html" with representative=todays_mep cols=12 %}
{% else %}
No MEP in database
{% endif %}
</div>
</div>
......
......@@ -32,10 +32,13 @@ class HomeView(PositionFormMixin, RepresentativeViewMixin,
qs = qs.select_related('representative_score')
random.seed(datetime.date.today().isoformat())
index = random.randint(0, qs.count() - 1)
c['todays_mep'] = qs.all()[index]
self.add_representative_country_and_main_mandate(c['todays_mep'])
qs_count = qs.count()
if qs_count > 0:
index = random.randint(0, (qs.count() - 1) or 1)
c['todays_mep'] = qs.all()[index]
self.add_representative_country_and_main_mandate(c['todays_mep'])
else:
c['todays_mep'] = None
# Featured themes
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment