[v2,1/4] filters: Return dictionaries

Message ID 20180929212610.29905-1-stephen@that.guru
State Accepted
Headers show
Series
  • [v2,1/4] filters: Return dictionaries
Related show

Commit Message

Stephen Finucane Sept. 29, 2018, 9:26 p.m.
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@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(-)

Comments

Stephen Finucane Oct. 13, 2018, 4:26 p.m. | #1
On Sat, 2018-09-29 at 22:26 +0100, Stephen Finucane wrote:
> 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@that.guru>

The comments from v1 were addressed and this issue has been around for
too long as-is. I've gone ahead and applied this and will backport
shortly.

Stephen

Patch

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':