Skip to content

Commit

Permalink
agregando lstas de parlamentarios
Browse files Browse the repository at this point in the history
  • Loading branch information
Felipe Álvarez committed May 7, 2018
1 parent 4c2dad0 commit 65473a6
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 4 deletions.
24 changes: 24 additions & 0 deletions elections/tests/version2/elections_per_area_tests.py
Expand Up @@ -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")
Expand Down
12 changes: 12 additions & 0 deletions elections/views.py
Expand Up @@ -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
24 changes: 24 additions & 0 deletions votai_general_theme/templates/_candidate_small.html
@@ -0,0 +1,24 @@
{% load thumbnail %}
{% load static %}
{% load i18n %}
<div class="col-md-2">
<div class="panel-heading text-center">
<a href="{{candidate.get_absolute_url}}">
{% if candidate.image %}
{% thumbnail candidate.image "200x200" crop="center" as im %}
<img src="{{ im.url }}" alt="{{ candidate.name }}" border="0" class="img-responsive img-circle" itemprop="image" />
{% endthumbnail %}
{% else %}
<img src="{% static 'img/candidate-default.jpg' %}" alt="{{candidate.name}}" border="0" class="img-responsive img-circle">
{% endif %}
</a>
<div class="panel-body text-center">
<a href="{{candidate.get_absolute_url}}" itemprop="name"><h3 class="candidate-name-card">{{ candidate.name }}</h3>
{% if candidate.commitments.exists %}
<p class="candidate-commitment-card">{% blocktrans with commitments_count=candidate.commitments.count %}
{{ commitments_count }} compromisos
{% endblocktrans %}</p></a>
{% endif %}
</div>
</div>
</div>
18 changes: 14 additions & 4 deletions votai_general_theme/templates/know_your_candidates.html
Expand Up @@ -11,11 +11,21 @@
<h1 class="text-center">{% trans "Congresistas comprometidos" %}</h1>
<p class="bajada text-center">{% trans "Encuentra aquí los nuevos/as diputados/as y senadores/as y sus compromisos con propuestas ciudadanas de votainteligente.cl" %}</p>

<div class="container">
{% include "_election_search_form.html" %}
</div>

</div>
{% display_election_card default_election %}

<div class="container">
{% for pos in positions %}
<h2>{{pos.name}}</h2>
<div class="row">
{% for candidate in pos.candidates %}
{% include "_candidate_small.html" with candidate=candidate%}
{% if forloop.counter|divisibleby:6 %}
</div><div class="row">
{% endif %}
{% endfor %}
</div>

{% endfor %}
</div>
{% endblock everything %}
1 change: 1 addition & 0 deletions votainteligente/settings.py
Expand Up @@ -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'),
Expand Down

0 comments on commit 65473a6

Please sign in to comment.