From 9436c15f5ba36c2c363385ad864b5f500c2ebccb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felipe=20=C3=81lvarez?= Date: Tue, 12 Nov 2013 13:53:41 -0300 Subject: [PATCH] Adding Questions per candidate page --- .../elections/questions_per_candidate.html | 9 ++++++--- .../tests/questions_per_candidate_view_tests.py | 16 +++++++--------- elections/views.py | 8 +++++++- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/elections/templates/elections/questions_per_candidate.html b/elections/templates/elections/questions_per_candidate.html index 54be0d57..300c2cb1 100644 --- a/elections/templates/elections/questions_per_candidate.html +++ b/elections/templates/elections/questions_per_candidate.html @@ -1,6 +1,7 @@ {% extends "elections/election_base.html" %} {% load i18n %} {% load votainteligente_extras %} +{% load pagination_tags %} {% block extrajs %} {% endblock extrajs %} @@ -9,8 +10,10 @@ {% block content %} {{ candidate }} - -{% for message in candidate.relation.person.messages.all %} - {% include 'elections/message_in_list.html' with message=message %} +{% autopaginate questions 2 %} +{% paginate %} +{% for question in questions %} + {% include 'elections/message_in_list.html' with message=question %} {% endfor %} +{% paginate %} {% endblock content %} \ No newline at end of file diff --git a/elections/tests/questions_per_candidate_view_tests.py b/elections/tests/questions_per_candidate_view_tests.py index e94fab0e..1277c16d 100644 --- a/elections/tests/questions_per_candidate_view_tests.py +++ b/elections/tests/questions_per_candidate_view_tests.py @@ -27,15 +27,13 @@ def setUp(self): self.candidate4.relation.person.id ] ).delete() - #Trying to copy it from - #https://github.com/ciudadanointeligente/votainteligente-primarias/blob/master/elecciones/tests/ranking.py self.message1 = VotaInteligenteMessage.objects.create(api_instance=self.election.writeitinstance.api_instance , author_name='author' , author_email='author email' , subject = u'subject test_accept_message' - , content = u'Qué opina usted sobre el test_accept_message' + , content = u'Que opina usted sobre el test_accept_message' , writeitinstance=self.election.writeitinstance , slug = 'subject-slugified' ) @@ -54,7 +52,7 @@ def setUp(self): , author_name='author' , author_email='author email' , subject = u'subject test_accept_message2' - , content = u'Qué opina usted sobre el test_accept_message2' + , content = u'Que opina usted sobre el test_accept_message2' , writeitinstance=self.election.writeitinstance , slug = 'subject-slugified' ) @@ -78,7 +76,7 @@ def setUp(self): , author_name='author' , author_email='author email' , subject = u'subject test_accept_message3' - , content = u'Qué opina usted sobre el test_accept_message3' + , content = u'Que opina usted sobre el test_accept_message3' , writeitinstance=self.election.writeitinstance , slug = 'subject-slugified' ) @@ -107,23 +105,23 @@ def setUp(self): , author_name='author' , author_email='author email' , subject = u'subject test_accept_message4' - , content = u'Qué opina usted sobre el test_accept_message4' + , content = u'Que opina usted sobre el test_accept_message4' , writeitinstance=self.election.writeitinstance , slug = 'subject-slugified' ) self.message4.people.add(self.candidate1) self.message4.people.add(self.candidate2) self.message4.people.add(self.candidate3) - #this question wasn't asked to candidate 4 def test_it_is_reachable(self): reverse_url = reverse('questions_per_candidate', kwargs={'election_slug':self.election.slug, - 'slug':self.candidate1.relation.candidate.slug})#This is FUCKING UGLY - #there must be a way to rearchitect this shit so writing tests is easy + 'slug':self.candidate1.relation.candidate.slug}) response = self.client.get(reverse_url) self.assertEquals(response.status_code,200) self.assertIn('candidate', response.context) self.assertEquals(response.context['candidate'], self.candidate1.relation.candidate) self.assertTemplateUsed(response, 'elections/questions_per_candidate.html') + self.assertIn('questions', response.context) + self.assertEquals(list(response.context['questions']), list(VotaInteligenteMessage.objects.filter(people=self.candidate1))) diff --git a/elections/views.py b/elections/views.py index defe8f7d..dde5f756 100644 --- a/elections/views.py +++ b/elections/views.py @@ -1,4 +1,4 @@ -# Create your views here. +# coding=utf-8 from django.views.generic.edit import FormView from elections.forms import ElectionSearchByTagsForm from django.core.urlresolvers import reverse @@ -92,6 +92,12 @@ def get_queryset(self): queryset.filter(Q(election__slug=election_slug)) return queryset + + def get_context_data(self, **kwargs): + context = super(QuestionsPerCandidateView, self).get_context_data(**kwargs) + context['questions'] = VotaInteligenteMessage.objects.filter(people=self.object.relation.person) + return context + class ElectionAskCreateView(CreateView): model = Message form_class = MessageForm