diff --git a/elections/tests/version2/elections_per_area_tests.py b/elections/tests/version2/elections_per_area_tests.py index 5d90f5cb..88e6eddc 100644 --- a/elections/tests/version2/elections_per_area_tests.py +++ b/elections/tests/version2/elections_per_area_tests.py @@ -152,6 +152,30 @@ def test_area_index_view_if_not_default_area(self): self.assertEquals(response.status_code, 200) self.assertIsNone(response.context['default_election']) + @override_config(SHOW_ALL_CANDIDATES_IN_THIS_ORDER='senador, diputado', DEFAULT_AREA='argentina') + def test_get_all_candidates_if_show_all_candidates_is_true(self): + first_e = Election.objects.get(id=1) + first_e.position = 'diputado' + first_e.save() + second_e = Election.objects.get(id=2) + second_e.position = 'senador' + second_e.save() + argentina = Area.objects.create(name=u'Argentina', id='argentina') + election = Election.objects.create( + name='the name', + area=argentina) + url = reverse('know_your_candidates') + response = self.client.get(url) + self.assertEquals(response.status_code, 200) + self.assertEquals(response.context['default_election'], election) + self.assertIn('positions', response.context) + self.assertEquals(response.context['positions'][0]['name'], 'senador') + for c in second_e.candidates.all(): + self.assertIn(c, response.context['positions'][0]['candidates']) + self.assertEquals(response.context['positions'][1]['name'], 'diputado') + for c in first_e.candidates.all(): + self.assertIn(c, response.context['positions'][1]['candidates']) + def test_get_area_parents(self): child = Area.objects.create(name="children") mother = Area.objects.create(name="mother") diff --git a/elections/views.py b/elections/views.py index 284d2bdf..a36f5997 100644 --- a/elections/views.py +++ b/elections/views.py @@ -254,10 +254,22 @@ def get_context_data(self, **kwargs): class KnowYourCandidatesView(TemplateView): template_name = "know_your_candidates.html" + def append_all_other_candidates(self, context): + candidate_positions = config.SHOW_ALL_CANDIDATES_IN_THIS_ORDER.split(",") + context['positions'] = [] + for position in candidate_positions: + position = position.strip() + + candidates = Candidate.objects.filter(elections__position=position) + context['positions'].append({'name': position, 'candidates': candidates}) + return context + def get_context_data(self, **kwargs): context = super(KnowYourCandidatesView, self).get_context_data(**kwargs) election = Election.objects.filter(area__id=config.DEFAULT_AREA).first() if election and election.second_round: election = election.second_round context['default_election'] = election + if config.SHOW_ALL_CANDIDATES_IN_THIS_ORDER: + context = self.append_all_other_candidates(context) return context diff --git a/votai_general_theme/templates/_candidate_small.html b/votai_general_theme/templates/_candidate_small.html new file mode 100644 index 00000000..eea4d289 --- /dev/null +++ b/votai_general_theme/templates/_candidate_small.html @@ -0,0 +1,24 @@ +{% load thumbnail %} +{% load static %} +{% load i18n %} +
+
+ + {% if candidate.image %} + {% thumbnail candidate.image "200x200" crop="center" as im %} + {{ candidate.name }} + {% endthumbnail %} + {% else %} + {{candidate.name}} + {% endif %} + + +
+
diff --git a/votai_general_theme/templates/know_your_candidates.html b/votai_general_theme/templates/know_your_candidates.html index 56d64437..066f2aca 100644 --- a/votai_general_theme/templates/know_your_candidates.html +++ b/votai_general_theme/templates/know_your_candidates.html @@ -11,11 +11,21 @@

{% trans "Congresistas comprometidos" %}

{% trans "Encuentra aquí los nuevos/as diputados/as y senadores/as y sus compromisos con propuestas ciudadanas de votainteligente.cl" %}

-
- {% include "_election_search_form.html" %} -
- {% display_election_card default_election %} +
+{% for pos in positions %} +

{{pos.name}}

+
+ {% for candidate in pos.candidates %} + {% include "_candidate_small.html" with candidate=candidate%} + {% if forloop.counter|divisibleby:6 %} +
+ {% endif %} + {% endfor %} +
+ +{% endfor %} +
{% endblock everything %} diff --git a/votainteligente/settings.py b/votainteligente/settings.py index efd534e5..680a8d16 100644 --- a/votainteligente/settings.py +++ b/votainteligente/settings.py @@ -183,6 +183,7 @@ 'NAV_BAR': ('profiles, questionary, soulmate, facetoface, ask, ranking', 'Menu de navegacion'), 'NAV_BAR_VOTITA_DISPLAYED': (False, 'Desplegamos el navbar del votita??????'), 'SHOW_RIBBON_IN_CANDIDATE': (False, u"Debería aparecerles la franja roja que dice 'No se ha compormetido?'"), + 'SHOW_ALL_CANDIDATES_IN_THIS_ORDER': ("", u"Mostrar todos los candidatos en la parte de /candidatos? "), 'CAN_CREATE_TEST_PROPOSAL': (False, u'Se pueden crear propuestas de prueba?'), 'SEARCH_SUBSCRIPTION_ENABLED': (True, u'Suscribirse a una búsqueda está habilitado? esto sólo esconde los links.'), 'WEBSITE_METADATA_AUTHOR': ('', 'Nombre del autor'),