Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
luxcem
memopol
Commits
28f55629
Commit
28f55629
authored
Dec 25, 2016
by
Jamesie Pic
Browse files
Fix home on empty database
parent
cc400d9c
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/memopol/templates/home.html
View file @
28f55629
...
@@ -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>
...
...
src/memopol/views/home.py
View file @
28f55629
...
@@ -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
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment