dossier_list.py 1.03 KB
Newer Older
1
2
3
4
5
6
7
8
9
# coding: utf-8

from core.views import PaginationMixin

from django.db.models import Count
from django.views import generic

from representatives_votes.models import Dossier

Nicolas Joyard's avatar
Nicolas Joyard committed
10
11
from ..filters import DossierFilter

12
13
14

class DossierList(PaginationMixin, generic.ListView):

Nicolas Joyard's avatar
Nicolas Joyard committed
15
    current_filter = None
16
17
    queryset = Dossier.objects.prefetch_related(
        'proposals',
18
19
20
        'proposals__recommendation',
        'documents',
        'documents__chamber'
21
    ).annotate(
22
        nb_proposals=Count('proposals'),
23
24
        nb_recomm=Count('proposals__recommendation')
    ).order_by('-nb_recomm', '-reference')
Nicolas Joyard's avatar
Nicolas Joyard committed
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39

    def dossier_filter(self, qs):
        f = DossierFilter(self.request.GET, queryset=qs)
        self.current_filter = f
        return f.qs

    def get_queryset(self):
        qs = super(DossierList, self).get_queryset()
        qs = self.dossier_filter(qs)
        return qs

    def get_context_data(self, **kwargs):
        c = super(DossierList, self).get_context_data(**kwargs)
        c['filter'] = self.current_filter
        return c