Skip to content

Commit

Permalink
Adding Questions per candidate page
Browse files Browse the repository at this point in the history
  • Loading branch information
lfalvarez committed Nov 12, 2013
1 parent 58d6d3b commit 9436c15
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
9 changes: 6 additions & 3 deletions elections/templates/elections/questions_per_candidate.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{% extends "elections/election_base.html" %}
{% load i18n %}
{% load votainteligente_extras %}
{% load pagination_tags %}

{% block extrajs %}
{% endblock extrajs %}
Expand All @@ -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 %}
16 changes: 7 additions & 9 deletions elections/tests/questions_per_candidate_view_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
)
Expand All @@ -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'
)
Expand All @@ -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'
)
Expand Down Expand Up @@ -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)))
8 changes: 7 additions & 1 deletion elections/views.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 9436c15

Please sign in to comment.