views.py 1.44 KB
Newer Older
Jamesie Pic's avatar
Jamesie Pic committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# Project specific "glue" coupling of all apps
from django.db import models

from core.views import GridListMixin, PaginationMixin
from representatives import views as representatives_views
from representatives.models import Representative
from representatives_votes import views as representatives_votes_views
from representatives_votes.models import Dossier
from representatives_positions.forms import PositionForm
from representatives_recommendations.models import ScoredVote


class RepresentativeList(PaginationMixin, GridListMixin,
        representatives_views.RepresentativeList):

    queryset = Representative.objects.filter(
        active=True).select_related('score')


class RepresentativeDetail(representatives_views.RepresentativeDetail):
    queryset = Representative.objects.select_related('score')

    def get_queryset(self):
        qs = super(RepresentativeDetail, self).get_queryset()
        votes = ScoredVote.objects.select_related('proposal__recommendation')
        qs = qs.prefetch_related(models.Prefetch('votes', queryset=votes))
        return qs

    def get_context_data(self, **kwargs):
        c = super(RepresentativeDetail, self).get_context_data(**kwargs)
        c['position_form'] = PositionForm()
        self.add_representative_country_and_main_mandate(c['object'])
        return c


class DossierList(PaginationMixin, representatives_votes_views.DossierList):
    queryset = Dossier.objects.exclude(proposals__recommendation=None)