Skip to content
Extraits de code Groupes Projets
Valider 3b1ba349 rédigé par Nicolas Joyard's avatar Nicolas Joyard
Parcourir les fichiers

Add rep contact info to view dataset

parent 365ec31a
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -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
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter