From b5eb22bf6f4e409bb610acb782cadb00651df51e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felipe=20=C3=81lvarez?= Date: Wed, 10 Aug 2016 15:48:35 -0400 Subject: [PATCH] Agregando OGP things para los candidatos --- elections/models.py | 20 +++++++++++++++++++ elections/tests/candidatorg_views_tests.py | 15 ++++++++++++++ .../templates/elections/candidate_detail.html | 6 ++++++ 3 files changed, 41 insertions(+) diff --git a/elections/models.py b/elections/models.py index 8b849cc7..42350711 100644 --- a/elections/models.py +++ b/elections/models.py @@ -65,6 +65,8 @@ class Candidate(Person, ExtraInfoMixin): default_extra_info = settings.DEFAULT_CANDIDATE_EXTRA_INFO + ogp_enabled = True + @property def election(self): if self.elections.count() == 1: @@ -92,6 +94,24 @@ def get_absolute_url(self): 'slug': self.id }) + def ogp_title(self): + return u'{} en VotaInteligente'.format(self.name) + + def ogp_type(self): + return 'website' + + def ogp_url(self): + site = Site.objects.get_current() + url = "http://%s%s" % (site.domain, + self.get_absolute_url()) + return url + + def ogp_image(self): + site = Site.objects.get_current() + url = "http://%s%s" % (site.domain, + static('img/logo_vi_og.jpg')) + return url + class Meta: verbose_name = _("Candidato") verbose_name_plural = _("Candidatos") diff --git a/elections/tests/candidatorg_views_tests.py b/elections/tests/candidatorg_views_tests.py index 51d8bf7b..ef6dae09 100644 --- a/elections/tests/candidatorg_views_tests.py +++ b/elections/tests/candidatorg_views_tests.py @@ -7,6 +7,8 @@ from elections.models import Topic from popolo.models import Person from candidator.comparer import InformationHolder +from django.contrib.staticfiles.templatetags.staticfiles import static +from django.contrib.sites.models import Site class CandidateInElectionsViewsTestCase(TestCase): @@ -47,6 +49,7 @@ def test_candidate_get_absolute_url(self): 'slug': candidate.id }) self.assertEquals(candidate.get_absolute_url(), url_2) + def test_url_is_reachable(self): url = reverse('candidate_detail_view', kwargs={ 'election_slug': self.tarapaca.slug, @@ -61,6 +64,18 @@ def test_url_is_reachable(self): self.assertTemplateUsed(response, 'elections/candidate_detail.html') self.assertTemplateUsed(response, 'base.html') + def test_candidates_ogp(self): + site = Site.objects.get_current() + candidate = self.coquimbo.candidates.get(id=1) + self.assertTrue(candidate.ogp_enabled) + self.assertIn(candidate.name, candidate.ogp_title()) + self.assertEquals('website', candidate.ogp_type()) + expected_url = "http://%s%s" % (site.domain, + candidate.get_absolute_url()) + self.assertEquals(expected_url, candidate.ogp_url()) + expected_url = "http://%s%s" % (site.domain, + static('img/logo_vi_og.jpg')) + self.assertEquals(expected_url, candidate.ogp_image()) class QuestionaryInElectionsViewTestCase(TestCase): def setUp(self): diff --git a/votai_general_theme/templates/elections/candidate_detail.html b/votai_general_theme/templates/elections/candidate_detail.html index d35a43ed..a5b613ea 100644 --- a/votai_general_theme/templates/elections/candidate_detail.html +++ b/votai_general_theme/templates/elections/candidate_detail.html @@ -5,6 +5,7 @@ {% load markdown_deux_tags %} {% load votainteligente_extras %} {% load thumbnail %} +{% load ogp_tags %} {% block url_face_to_face %}{% url 'face_to_face_one_candidate_detail_view' slug=election.slug slug_candidate_one=candidate.id %}{% endblock url_face_to_face %} @@ -12,6 +13,11 @@ {% block tab_profile %}class="active"{% endblock %} +{% block ogp %} + {% render_ogp candidate %} +{% endblock ogp %} + + {% block mainelection %}