diff --git a/elections/models.py b/elections/models.py index 2768bf47..cbda02b0 100644 --- a/elections/models.py +++ b/elections/models.py @@ -23,6 +23,10 @@ class Meta: def get_absolute_url(self): return reverse('area', kwargs={'slug': self.id}) + @property + def elections_without_position(self): + return self.elections.filter(position__isnull=True).filter(position__exact='') + class ExtraInfoMixin(models.Model): extra_info = PickledObjectField(default={}) diff --git a/elections/tests/template_tags_tests.py b/elections/tests/template_tags_tests.py index b7ed6698..d45541b6 100644 --- a/elections/tests/template_tags_tests.py +++ b/elections/tests/template_tags_tests.py @@ -303,4 +303,40 @@ def test_user_image(self): 'width': 100})) template = Template("{% load votainteligente_extras %}{% user_image user=user height=120 width=100 %}") self.assertEqual(template.render(Context({'user': u, 'height': 120, 'width': 100})), - rendered_template) \ No newline at end of file + rendered_template) + + def test_get_election_by_position(self): + argentina = Area.objects.create(name=u'Argentina') + election = Election.objects.create( + name='the name', + slug='the-slug', + description='this is a description', + extra_info_title=u'ver más', + area=argentina, + position='alcalde', + extra_info_content=u'Más Información') + + template = Template("{% load votainteligente_extras %}{% get_election_by_position 'alcalde' as election %}{{election.name}}") + context = Context({'area': argentina}) + rendered_template = template.render(context) + self.assertEquals(election.name, rendered_template) + template2 = Template("{% load votainteligente_extras %}{% get_election_by_position 'concejal' as election %}{{election.name}}") + self.assertFalse(template2.render(context)) + chile = Area.objects.create(name=u'Chile') + election.area = chile + election.save() + template3 = Template("{% load votainteligente_extras %}{% get_election_by_position 'alcalde' as election %}{{election.name}}") + self.assertFalse(template3.render(context)) + + # Two elections with the same position doesn't raise error + election.area = argentina + election.save() + election = Election.objects.create( + name='the name2', + slug='the-slug', + description='this is a description', + extra_info_title=u'ver más', + area=argentina, + position='alcalde', + extra_info_content=u'Más Información') + self.assertTrue(template.render(context)) \ No newline at end of file diff --git a/elections/tests/version2/elections_per_area_tests.py b/elections/tests/version2/elections_per_area_tests.py index 87664c31..66aac2fc 100644 --- a/elections/tests/version2/elections_per_area_tests.py +++ b/elections/tests/version2/elections_per_area_tests.py @@ -44,4 +44,19 @@ def test_ogp_things(self): self.assertEquals(expected_url, self.argentina.ogp_url()) expected_url = "http://%s%s" % (self.site.domain, static('img/logo_vi_og.jpg')) - self.assertEquals(expected_url, self.argentina.ogp_image()) \ No newline at end of file + self.assertEquals(expected_url, self.argentina.ogp_image()) + + def test_area_elections_without_position(self): + election = Election.objects.create( + name='the name', + slug='the-slug', + description='this is a description', + extra_info_title=u'ver más', + area=self.argentina, + position='alcalde', + extra_info_content=u'Más Información') + + elections_without_position = self.argentina.elections_without_position.all() + self.assertNotIn(election, elections_without_position) + self.assertIn(election, self.argentina.elections.all()) + diff --git a/votai_general_theme/templates/elections/_election_with_position.html b/votai_general_theme/templates/elections/_election_with_position.html new file mode 100644 index 00000000..defd8055 --- /dev/null +++ b/votai_general_theme/templates/elections/_election_with_position.html @@ -0,0 +1,38 @@ +{% load votainteligente_extras %} +{% load thumbnail %} +{% load staticfiles %} +{% load i18n %} +{% load thumbnail %} +{% load bootstrap3 %} + +{% get_election_by_position position as election %} + +
  • + + +

    {{ election.name }}

    +
    +

    {{ election.description|truncatewords:33 }}

    +
    +
  • \ No newline at end of file diff --git a/votai_general_theme/templates/elections/area.html b/votai_general_theme/templates/elections/area.html index 48b5ccf4..328e2b94 100644 --- a/votai_general_theme/templates/elections/area.html +++ b/votai_general_theme/templates/elections/area.html @@ -5,6 +5,7 @@ {% load bootstrap3 %} {% load ogp_tags %} + {% block extrajs %} $(function(){ $('.loadFromUrl').on('show.bs.modal', function (event) { @@ -46,11 +47,29 @@

    {{area.name}}

    - + +