From c9101d253a983486fbb5b03082ef1b7395e22e1f Mon Sep 17 00:00:00 2001
From: Nicolas Joyard <joyard.nicolas@gmail.com>
Date: Fri, 10 Jun 2016 21:05:33 +0200
Subject: [PATCH] Add pagination and active filter to group views

---
 memopol/views/group_list.py               | 15 +++++---
 templates/representatives/group_list.haml | 44 ++++++++++++-----------
 2 files changed, 34 insertions(+), 25 deletions(-)

diff --git a/memopol/views/group_list.py b/memopol/views/group_list.py
index eb500f71..638e73fe 100644
--- a/memopol/views/group_list.py
+++ b/memopol/views/group_list.py
@@ -2,19 +2,24 @@
 
 import datetime
 
+from core.views import PaginationMixin, ActiveLegislatureMixin
+
 from django.db import models
 from django.views import generic
 
 from representatives.models import Group
 
 
-class GroupList(generic.ListView):
+class GroupList(PaginationMixin, ActiveLegislatureMixin, generic.ListView):
 
     def get_queryset(self):
-        qs = Group.objects.filter(
-            models.Q(mandates__end_date__gte=datetime.date.today()) |
-            models.Q(mandates__end_date__isnull=True)
-        )
+        qs = Group.objects.all()
+
+    	if self.get_active_only():
+	        qs = qs.filter(
+	            models.Q(mandates__end_date__gte=datetime.date.today()) |
+	            models.Q(mandates__end_date__isnull=True)
+	        )
 
         kind = self.kwargs.get('kind', None)
         if kind:
diff --git a/templates/representatives/group_list.haml b/templates/representatives/group_list.haml
index b009e463..d2201929 100644
--- a/templates/representatives/group_list.haml
+++ b/templates/representatives/group_list.haml
@@ -3,25 +3,29 @@
 - load memopol_tags
 - load representatives_tags
 
-
 - block content
-  %table.table
-    - for group in object_list
-      %tr
-        - if group.kind != 'country' and group.kind != 'chamber'
-          %td
-            %a{'href': "{% chamber_url group.chamber %}"}
-              = group.chamber|chamber_icon
 
-        %td
-          %a{'href': "{% group_url group %}"}
-            - if group.abbreviation
-              ={group.abbreviation}
-        %td
-          %a{'href': "{% group_url group %}"}=
-            - if group.kind == 'chamber'
-              = group|chamber_icon
-            - elif group.kind == 'group'
-              = group|group_long_icon
-            - else
-              = group.name
+  - include 'core/blocks/pagination.html'
+
+  - block list
+
+    %table.table
+      - for group in object_list
+        %tr
+          - if group.kind != 'country' and group.kind != 'chamber'
+            %td
+              %a{'href': "{% chamber_url group.chamber %}"}
+                = group.chamber|chamber_icon
+
+          %td
+            %a{'href': "{% group_url group %}"}
+              - if group.abbreviation
+                ={group.abbreviation}
+          %td
+            %a{'href': "{% group_url group %}"}=
+              - if group.kind == 'chamber'
+                = group|chamber_icon
+              - elif group.kind == 'group'
+                = group|group_long_icon
+              - else
+                = group.name
-- 
GitLab