Commit c04c089e authored by Nicolas Joyard's avatar Nicolas Joyard

Add chamber links and refactor contact block a bit

parent e016d3f5
......@@ -109,6 +109,16 @@ def chamber_small_icon(chamber):
u'title="{name}"></span>'.format(name=chamber.name, url=url))
@register.simple_tag
def chamber_page_link(site, name):
icon_url = static('images/chamber-%s.png' % cssify(site.kind))
site_url = fix_url(site.url)
return mark_safe(
u'<span class="chamber-icon" style="background-image: url({icon})" '
u'></span> <a href="{site}" target="_blank">{name}</a>'
.format(name=name, site=site_url, icon=icon_url))
@register.filter
def mandate_icon(main_mandate):
group = main_mandate.group
......
......@@ -12,13 +12,15 @@ class RepresentativeDetailTest(UrlGetTestMixin, TestCase):
# Ensure one-time cached queries occur before the actual test
self.client.get(self.url)
with self.assertNumQueries(10):
with self.assertNumQueries(12):
"""
- One query for chambers
- One query for the rep details and foreign key (profile)
- One query for reverse relation on phones
- One query for reverse relation on addresses
- One query for reverse relation on emails
- Two queries for reverse relation on websites (social and other)
- Three queries for reverse relation on websites (parliament,
social and other)
- One query for reverse relation on votes
- One query for reverse relation on mandates
- One query for reverse relation positions
......
......@@ -3,7 +3,8 @@
from django.db import models
from django.views import generic
from representatives.models import Representative, Address, Phone, WebSite
from representatives.models import Chamber, Representative, Address, Phone, \
WebSite
from representatives_positions.forms import PositionForm
from representatives_recommendations.models import VoteScore
from representatives_votes.models import Proposal
......@@ -21,6 +22,9 @@ class RepresentativeDetail(RepresentativeViewMixin, generic.DetailView):
qs = self.prefetch_for_representative_country_and_main_mandate(qs)
social = ['twitter', 'facebook']
chambers = [c['abbreviation']
for c in Chamber.objects.values('abbreviation')]
qs = qs.prefetch_related(
'email_set',
models.Prefetch(
......@@ -30,7 +34,13 @@ class RepresentativeDetail(RepresentativeViewMixin, generic.DetailView):
),
models.Prefetch(
'website_set',
queryset=WebSite.objects.exclude(kind__in=social),
queryset=WebSite.objects.filter(kind__in=chambers),
to_attr='chamber_websites'
),
models.Prefetch(
'website_set',
queryset=WebSite.objects.exclude(kind__in=social)
.exclude(kind__in=chambers),
to_attr='other_websites'
),
models.Prefetch(
......
......@@ -39,20 +39,3 @@
Born in {{ representative.birth_place }} the
{{ representative.birth_date|naturalday:'d/m/Y' }}
({{ representative.get_gender_display }})
- if representative.social_websites|length > 0
%tr
%th Social
%td
- for site in representative.social_websites
- if site.kind == 'twitter'
= site.url|twitter_link
- elif site.kind == 'facebook'
= site.url|facebook_link
- if representative.other_websites|length > 0
%tr
%th Websites
%td
- for site in representative.other_websites
= site.url|website_link
......@@ -4,18 +4,54 @@
.col-md-12
%h2 Contact information
%table.table.table-condensed.detail-view
- for site in representative.chamber_websites
%tr
- if forloop.first
%th{rowspan: '{{representative.chamber_websites|length}}'}
Parliamentary pages
%td
- chamber_page_link site representative.full_name
- for site in representative.social_websites
%tr
- if forloop.first
%th{rowspan: '{{representative.social_websites|length}}'}
Social networks
%td
- if site.kind == 'twitter'
= site.url|twitter_link
- elif site.kind == 'facebook'
= site.url|facebook_link
- for site in representative.other_websites
%tr
- if forloop.first
%th{rowspan: '{{representative.other_websites|length}}'}
Websites
%td
= site.url|website_link
- for email in representative.email_set.all
%tr
%th E-mail
- if forloop.first
%th{rowspan: '{{representative.email_set.all|length}}'}
E-mail
%td
= email.email|email_link
- if representative.phone_set.all|length > 0
- for phone in representative.phone_set.all
%tr
%th Phone numbers
- if forloop.first
%th{rowspan: '{{representative.phone_set.all|length}}'}
Phone numbers
%td
- for phone in representative.phone_set.all
.phone {{ phone.number }}
.phone {{ phone.number }}
- for address in representative.address_set.all
%tr
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment