dossier_list.py 1001 Bytes
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
18
19
    queryset = Dossier.objects.prefetch_related(
        'proposals',
        'proposals__recommendation'
    ).annotate(
20
        nb_proposals=Count('proposals'),
21
22
        nb_recomm=Count('proposals__recommendation')
    ).order_by('-nb_recomm', '-reference')
Nicolas Joyard's avatar
Nicolas Joyard committed
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37

    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