diff --git a/src/memopol/static/css/custom.css b/src/memopol/static/css/custom.css index bf48836be3e253512bc4c25c7d7d655059c74806..a978840a44ac4c2bfa05ad94d8ba5b2d2ab38df0 100755 --- a/src/memopol/static/css/custom.css +++ b/src/memopol/static/css/custom.css @@ -261,7 +261,7 @@ a:hover .custom-thumbnail-details { position: relative; } -.custom-listMEP .thumbnail .badge, +.representative-card .thumbnail .badge, .position-button .badge { position: absolute; top: -0.5em; @@ -333,6 +333,12 @@ iframe { background-size: cover; } +.todays-mep .representative-card .img-responsive { + width: 150px; + height: 150px; +} + + .representative-card h4 { margin-top: 15px; } diff --git a/src/memopol/templates/home.html b/src/memopol/templates/home.html index 8a411f19de13e8a5bdbecc7194dbcdb53d515d1b..ba09677ab98a56d3628008489517bcf70b3b8877 100644 --- a/src/memopol/templates/home.html +++ b/src/memopol/templates/home.html @@ -21,6 +21,20 @@

+
+ placeholder +
+ +
+ placeholder +
+ +
+

{% trans "Today's Representative" %}

+ + {% include "representatives/_representative_card.html" with representative=todays_mep cols=12 %} +
+

{% trans "More information" %}

diff --git a/src/memopol/templates/representatives/_representative_card.html b/src/memopol/templates/representatives/_representative_card.html new file mode 100644 index 0000000000000000000000000000000000000000..75dc373905542eb3273b8b29b81aca82b079d229 --- /dev/null +++ b/src/memopol/templates/representatives/_representative_card.html @@ -0,0 +1,42 @@ +{% load memopol_tags %} + + \ No newline at end of file diff --git a/src/memopol/templates/representatives/representative_grid.html b/src/memopol/templates/representatives/representative_grid.html index 32b775a72dd6e56e1a9358a3b082a66f18e96296..2cb749825c11b9029bbe35512501d2408099de83 100644 --- a/src/memopol/templates/representatives/representative_grid.html +++ b/src/memopol/templates/representatives/representative_grid.html @@ -1,6 +1,5 @@ {% extends 'base.html' %} {% load i18n %} -{% load memopol_tags %} {% block title %}{% trans "Members of the European Parliement" %}{% endblock %} @@ -15,47 +14,8 @@ {% include "blocks/listheader.html" %}
- {% for representative in object_list %} - + {% for mep in object_list %} + {% include "representatives/_representative_card.html" with representative=mep cols=4 %} {% empty %} {% trans "No representatives found !" %} {% endfor %} diff --git a/src/memopol/views/home.py b/src/memopol/views/home.py index ff5566d76f61ac013933f4d60296fc64969bed05..063412f03bd4eb15645198ec7cf498443d0bcf4d 100644 --- a/src/memopol/views/home.py +++ b/src/memopol/views/home.py @@ -1,9 +1,33 @@ # coding: utf-8 +import datetime +import random + +from django.db.models import Q from django.views import generic +from representatives.models import Representative from representatives_positions.views import PositionFormMixin +from .representative_mixin import RepresentativeViewMixin + -class HomeView(PositionFormMixin, generic.TemplateView): +class HomeView(PositionFormMixin, RepresentativeViewMixin, + generic.TemplateView): template_name = 'home.html' + + def get_context_data(self, **kwargs): + c = super(HomeView, self).get_context_data(**kwargs) + + qs = Representative.objects + qs = qs.filter(Q(representative_score__score__lt=0) | + Q(representative_score__score__gt=0)) + qs = self.prefetch_for_representative_country_and_main_mandate(qs) + + 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']) + + return c