From fbfd31269879e06101cd7944c7753c5806c7c61f Mon Sep 17 00:00:00 2001
From: Nicolas Joyard <joyard.nicolas@gmail.com>
Date: Sat, 28 May 2016 17:36:25 +0200
Subject: [PATCH] Enhance dossier list a bit

---
 memopol/views.py                                  |  8 +++++++-
 templates/_header.haml                            |  2 +-
 templates/representatives_votes/dossier_list.haml | 13 ++++++++++++-
 3 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/memopol/views.py b/memopol/views.py
index fb7ab10a..ff734b4f 100644
--- a/memopol/views.py
+++ b/memopol/views.py
@@ -1,5 +1,6 @@
 # Project specific "glue" coupling of all apps
 from django.db import models
+from django.db.models import Count
 
 from core.views import GridListMixin, PaginationMixin, CSVDownloadMixin
 from representatives import views as representatives_views
@@ -82,4 +83,9 @@ class RepresentativeDetail(representatives_views.RepresentativeDetail):
 
 
 class DossierList(PaginationMixin, representatives_votes_views.DossierList):
-    queryset = Dossier.objects.exclude(proposals__recommendation=None)
+    queryset = Dossier.objects.prefetch_related(
+        'proposals',
+        'proposals__recommendation'
+    ).annotate(
+        nb_recomm=Count('proposals__recommendation')
+    ).order_by('-reference')
diff --git a/templates/_header.haml b/templates/_header.haml
index a1670f4a..b0dd05f5 100644
--- a/templates/_header.haml
+++ b/templates/_header.haml
@@ -34,4 +34,4 @@
         - trans 'Committees'
     %li
       %a{href: "{% url 'representatives_votes:dossier-list' %}"}
-        - trans 'Votes'
+        - trans 'Dossiers'
diff --git a/templates/representatives_votes/dossier_list.haml b/templates/representatives_votes/dossier_list.haml
index 2f3e2cc6..15d1bab1 100644
--- a/templates/representatives_votes/dossier_list.haml
+++ b/templates/representatives_votes/dossier_list.haml
@@ -1,14 +1,25 @@
 - extends "base.html"
+- load i18n
 
 - block content
-  %h1 Dossiers
+  %h1
+    - trans "Dossiers"
 
   %table.table
+    %tr
+      %th
+        - trans "Title"
+      %th
+        - trans "Recommendations"
+      %th
+        - trans "Reference"
+
     - for dossier in object_list
       %tr
         %td
           %a{'href': "{{ dossier.get_absolute_url }}"}
             {{ dossier.title }}
+        %td= dossier.nb_recomm
         %td= dossier.reference
 
   - include "core/blocks/pagination.html"
-- 
GitLab