representative_mandates.py 809 Bytes
Newer Older
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
# coding: utf-8

from django.views import generic

from representatives.models import Representative

from .representative_mixin import RepresentativeViewMixin


class RepresentativeMandates(RepresentativeViewMixin, generic.DetailView):
    template_name = 'representatives/representative_mandates'

    queryset = Representative.objects.select_related('score')

    def get_queryset(self):
        qs = super(RepresentativeMandates, self).get_queryset()

        qs = self.prefetch_for_representative_country_and_main_mandate(qs)

        return qs

    def get_context_data(self, **kwargs):
        c = super(RepresentativeMandates, self).get_context_data(**kwargs)

        self.add_representative_country_and_main_mandate(c['object'])

        c['mandates'] = c['object'].mandates.all()

        return c