From b2747903a49d74f5be84e24a96d99579f36ec8b9 Mon Sep 17 00:00:00 2001
From: Nicolas Joyard <joyard.nicolas@gmail.com>
Date: Fri, 17 Jun 2016 19:08:21 +0200
Subject: [PATCH] Add no results message and test

---
 memopol/tests/test_representatives_list.py    |  3 +
 static/scss/filter.scss                       |  8 ++
 .../representatives/representative_list.haml  | 94 ++++++++++---------
 3 files changed, 61 insertions(+), 44 deletions(-)

diff --git a/memopol/tests/test_representatives_list.py b/memopol/tests/test_representatives_list.py
index 876120c3..cda54584 100644
--- a/memopol/tests/test_representatives_list.py
+++ b/memopol/tests/test_representatives_list.py
@@ -122,3 +122,6 @@ class RepresentativeListTest(UrlGetTestMixin, TestCase):
 
     def test_filter_multiple(self):
         self.filter_test('e', 110, 1, 17)
+
+    def test_filter_notfound(self):
+        self.filter_test('non-existing-rep-name')
diff --git a/static/scss/filter.scss b/static/scss/filter.scss
index 6edf3981..7d0209fe 100644
--- a/static/scss/filter.scss
+++ b/static/scss/filter.scss
@@ -59,4 +59,12 @@
       }
     }
   }
+}
+
+.no-results {
+  margin-top: 1em;
+  font-size: larger;
+  font-weight: bold;
+  color: #555;
+  margin: 2em 0;
 }
\ No newline at end of file
diff --git a/templates/representatives/representative_list.haml b/templates/representatives/representative_list.haml
index 087f2f11..d745a7b8 100644
--- a/templates/representatives/representative_list.haml
+++ b/templates/representatives/representative_list.haml
@@ -15,47 +15,53 @@
     {% url 'representative-list' as action_url %}
     - include 'representatives/_filter_form.html' with action=action_url form=filter.form qs=request.GET.urlencode
 
-  - include 'core/blocks/pagination.html'
-
-  - block list
-
-    %table.table
-      %tr
-        %th
-          - trans 'Photo'
-        %th
-          - trans 'Name'
-        %th
-          - trans 'Chamber'
-        %th
-          - trans 'Country'
-        %th
-          - trans 'Group'
-        %th
-          - trans 'Score'
-
-      - for representative in object_list
-        %tr.representative_item{'class': '{{ representative.active|yesno:"active,inactive" }}'}
-          %td.photo
-            %a{'href': "{% url 'representative-detail' representative.slug %}"}
-              %img{'src': '={representative.photo}', 'width': '80'}/
-
-          %td
-            %a{'href': "{% url 'representative-detail' representative.slug %}"}
-              = representative.full_name
-
-          %td
-            %a{'href': "{% chamber_url representative.chamber %}"}
-              = representative.chamber
-
-          %td
-            %a{'href': "{% country_url representative.country %}"}
-              = representative.country
-
-          %td
-            %a{'href': "{% group_url representative.main_mandate.group %}"}
-              = representative.main_mandate.group|group_icon
-          %td
-            = representative.score.score|score_label
-
-  - include 'core/blocks/pagination.html'
+  - if object_list|length == 0
+
+      .no-results="No matching representatives found :("
+
+  - else
+
+    - include 'core/blocks/pagination.html'
+
+    - block list
+
+      %table.table
+        %tr
+          %th
+            - trans 'Photo'
+          %th
+            - trans 'Name'
+          %th
+            - trans 'Chamber'
+          %th
+            - trans 'Country'
+          %th
+            - trans 'Group'
+          %th
+            - trans 'Score'
+
+        - for representative in object_list
+          %tr.representative_item{'class': '{{ representative.active|yesno:"active,inactive" }}'}
+            %td.photo
+              %a{'href': "{% url 'representative-detail' representative.slug %}"}
+                %img{'src': '={representative.photo}', 'width': '80'}/
+
+            %td
+              %a{'href': "{% url 'representative-detail' representative.slug %}"}
+                = representative.full_name
+
+            %td
+              %a{'href': "{% chamber_url representative.chamber %}"}
+                = representative.chamber
+
+            %td
+              %a{'href': "{% country_url representative.country %}"}
+                = representative.country
+
+            %td
+              %a{'href': "{% group_url representative.main_mandate.group %}"}
+                = representative.main_mandate.group|group_icon
+            %td
+              = representative.score.score|score_label
+
+    - include 'core/blocks/pagination.html'
-- 
GitLab