Commit 3b1ba349 authored by Nicolas Joyard's avatar Nicolas Joyard
Browse files

Add rep contact info to view dataset

parent 365ec31a
......@@ -3,7 +3,7 @@ from django.db import models
from core.views import GridListMixin, PaginationMixin, CSVDownloadMixin
from representatives import views as representatives_views
from representatives.models import Representative
from representatives.models import (Representative, Address, Phone, WebSite)
from representatives_votes import views as representatives_votes_views
from representatives_votes.models import Dossier, Proposal
from representatives_positions.forms import PositionForm
......@@ -41,11 +41,34 @@ class RepresentativeDetail(representatives_views.RepresentativeDetail):
queryset = Representative.objects.select_related('score')
def get_queryset(self):
qs = super(RepresentativeDetail, self).get_queryset()
votes = VoteScore.objects.filter(
proposal__in=Proposal.objects.exclude(recommendation=None),
).select_related('proposal__recommendation')
qs = qs.prefetch_related(models.Prefetch('votes', queryset=votes))
social = ['twitter', 'facebook']
qs = super(RepresentativeDetail, self).get_queryset().prefetch_related(
'email_set',
models.Prefetch(
'website_set',
queryset=WebSite.objects.filter(kind__in=social),
to_attr='social_websites'
),
models.Prefetch(
'website_set',
queryset=WebSite.objects.exclude(kind__in=social),
to_attr='other_websites'
),
models.Prefetch(
'address_set',
queryset=Address.objects.select_related('country')
),
models.Prefetch(
'phone_set',
queryset=Phone.objects.select_related('address__country')
),
models.Prefetch(
'votes',
queryset=VoteScore.objects.filter(
proposal__in=Proposal.objects.exclude(recommendation=None),
).select_related('proposal__recommendation')
)
)
return qs
def get_context_data(self, **kwargs):
......@@ -53,6 +76,7 @@ class RepresentativeDetail(representatives_views.RepresentativeDetail):
c['position_form'] = PositionForm(
initial={'representative': self.object.pk})
self.add_representative_country_and_main_mandate(c['object'])
return c
......
Supports Markdown
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