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

Fix home on empty database

parent cc400d9c
...@@ -79,7 +79,11 @@ ...@@ -79,7 +79,11 @@
<div class="col-md-4 todays-mep"> <div class="col-md-4 todays-mep">
<h2>{% trans "Today's Representative" %}</h2> <h2>{% trans "Today's Representative" %}</h2>
{% if todays_mep %}
{% include "representatives/_representative_card.html" with representative=todays_mep cols=12 %} {% include "representatives/_representative_card.html" with representative=todays_mep cols=12 %}
{% else %}
No MEP in database
{% endif %}
</div> </div>
</div> </div>
......
...@@ -32,10 +32,13 @@ class HomeView(PositionFormMixin, RepresentativeViewMixin, ...@@ -32,10 +32,13 @@ class HomeView(PositionFormMixin, RepresentativeViewMixin,
qs = qs.select_related('representative_score') qs = qs.select_related('representative_score')
random.seed(datetime.date.today().isoformat()) random.seed(datetime.date.today().isoformat())
index = random.randint(0, qs.count() - 1) qs_count = qs.count()
c['todays_mep'] = qs.all()[index] if qs_count > 0:
index = random.randint(0, (qs.count() - 1) or 1)
self.add_representative_country_and_main_mandate(c['todays_mep']) c['todays_mep'] = qs.all()[index]
self.add_representative_country_and_main_mandate(c['todays_mep'])
else:
c['todays_mep'] = None
# Featured themes # Featured themes
......
Supports Markdown
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