From 7da6745b3b555a98405029fa90851881a95cd7ba Mon Sep 17 00:00:00 2001
From: Nicolas Joyard <joyard.nicolas@gmail.com>
Date: Thu, 16 Jun 2016 19:53:53 +0200
Subject: [PATCH] Separate filter form & integrate csv button

---
 templates/representatives/_filter_form.haml       | 15 +++++++++++++++
 .../representatives/representative_list.haml      | 14 ++++++--------
 2 files changed, 21 insertions(+), 8 deletions(-)
 create mode 100644 templates/representatives/_filter_form.haml

diff --git a/templates/representatives/_filter_form.haml b/templates/representatives/_filter_form.haml
new file mode 100644
index 00000000..1940d5fc
--- /dev/null
+++ b/templates/representatives/_filter_form.haml
@@ -0,0 +1,15 @@
+- load bootstrap3
+
+%form.filter-form{'action': '{{action}}', 'method': 'get'}
+
+  - bootstrap_form form=form bound_css_class='filter-form-group'
+
+  - buttons
+    %button{'type': 'submit', 'class': 'btn btn-primary'}
+      {% bootstrap_icon "filter" %} Filter
+  - endbuttons
+
+  - buttons
+    %a{'href': '?{{ qs }}&csv', 'class': 'btn btn-primary'}
+      {% bootstrap_icon "download-alt" %} Download as CSV
+  - endbuttons
diff --git a/templates/representatives/representative_list.haml b/templates/representatives/representative_list.haml
index 62038840..087f2f11 100644
--- a/templates/representatives/representative_list.haml
+++ b/templates/representatives/representative_list.haml
@@ -4,18 +4,16 @@
 - load memopol_tags
 - load representatives_recommendations_tags
 
-- block content
+- block head
 
-  - block search
+  {{ filter.form.media }}
 
-    {{ filter.form.media }}
+- block content
 
-    %form.filter-form{action:'', method:'get'}
-      {{ filter.form.as_p }}
-      %input{type:"submit", value:"Go"}
+  - block search
 
-    %a{href:"?{% if request.GET.search %}search={{ request.GET.search }}&{% endif %}csv"}
-      - trans 'Download data as CSV'
+    {% 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'
 
-- 
GitLab