[PATCH v2 1/4] filters: Return dictionaries

Stephen Finucane stephen at that.guru
Sun Sep 30 07:26:07 AEST 2018


This makes it a little easier to figure out what filters are active and
will be used in a future patch.

Signed-off-by: Stephen Finucane <stephen at that.guru>
---
v2:
- Return ordered dictionaries instead of dictionaries
---
 patchwork/filters.py                       | 13 ++++++++-----
 patchwork/templates/patchwork/filters.html |  2 +-
 patchwork/views/__init__.py                |  2 +-
 3 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/patchwork/filters.py b/patchwork/filters.py
index 6cfe41c9..dd7b00db 100644
--- a/patchwork/filters.py
+++ b/patchwork/filters.py
@@ -3,6 +3,8 @@
 #
 # SPDX-License-Identifier: GPL-2.0-or-later
 
+import collections
+
 from django.contrib.auth.models import User
 from django.utils.html import escape
 from django.utils.safestring import mark_safe
@@ -443,7 +445,7 @@ class Filters:
         self.project = project
 
     def filter_conditions(self):
-        kwargs = {}
+        kwargs = collections.OrderedDict()
         for f in self._filters:
             if f.applied:
                 kwargs.update(f.kwargs())
@@ -456,11 +458,11 @@ class Filters:
         return queryset.filter(**kwargs)
 
     def params(self):
-        return [(f.param, f.key()) for f in self._filters
-                if f.key() is not None]
+        return collections.OrderedDict([
+            (f.param, f.key()) for f in self._filters if f.key() is not None])
 
     def querystring(self, remove=None):
-        params = dict(self.params())
+        params = self.params()
 
         for (k, v) in self.values.items():
             if k not in params:
@@ -481,7 +483,8 @@ class Filters:
         return self.querystring(filter)
 
     def applied_filters(self):
-        return [x for x in self._filters if x.applied]
+        return collections.OrderedDict([
+            (x.param, x) for x in self._filters if x.applied])
 
     def available_filters(self):
         return self._filters
diff --git a/patchwork/templates/patchwork/filters.html b/patchwork/templates/patchwork/filters.html
index 5331ac85..e760310b 100644
--- a/patchwork/templates/patchwork/filters.html
+++ b/patchwork/templates/patchwork/filters.html
@@ -130,7 +130,7 @@ $(document).ready(function() {
  <div id="filtersummary">
   <a href="javascript:filter_click()">Show patches with</a>:
  {% if filters.applied_filters %}
-  {% for filter in filters.applied_filters %}
+  {% for filter in filters.applied_filters.values %}
    {{ filter.name }} = <strong>{{ filter.condition }}</strong>
     {% if not filter.forced %}
      <a class="filter-action"
diff --git a/patchwork/views/__init__.py b/patchwork/views/__init__.py
index 0c64c93e..cce00d67 100644
--- a/patchwork/views/__init__.py
+++ b/patchwork/views/__init__.py
@@ -190,7 +190,7 @@ def generic_list(request, project, view, view_args=None, filter_settings=None,
 
         value = data.get(param, None)
         if value:
-            params.append((param, value))
+            params['param'] = value
 
     data = {}
     if request.method == 'GET':
-- 
2.17.1



More information about the Patchwork mailing list