Skip to content

Commit

Permalink
Agregando OGP things para los candidatos
Browse files Browse the repository at this point in the history
  • Loading branch information
Felipe Álvarez committed Aug 10, 2016
1 parent 2973d8a commit b5eb22b
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
20 changes: 20 additions & 0 deletions elections/models.py
Expand Up @@ -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:
Expand Down Expand Up @@ -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")
Expand Down
15 changes: 15 additions & 0 deletions elections/tests/candidatorg_views_tests.py
Expand Up @@ -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):
Expand Down Expand Up @@ -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,
Expand All @@ -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):
Expand Down
6 changes: 6 additions & 0 deletions votai_general_theme/templates/elections/candidate_detail.html
Expand Up @@ -5,13 +5,19 @@
{% 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 %}

{% block title %} - {{election}} - {{candidate.name}}{% endblock title%}

{% block tab_profile %}class="active"{% endblock %}

{% block ogp %}
{% render_ogp candidate %}
{% endblock ogp %}


{% block mainelection %}
<div class="container-profile">
<div>
Expand Down

0 comments on commit b5eb22b

Please sign in to comment.