[PATCH v4 6/7] templates: Integrate series support

Stephen Finucane stephen at that.guru
Sun Oct 9 06:09:07 AEDT 2016


Integrate support for series in the web UI. This is rather
straightforward, the only significant change being the addition of a
filter for series filtering.

Signed-off-by: Stephen Finucane <stephen at that.guru>
---
v4:
- Update to use newly added Series.name field
---
 patchwork/filters.py                          | 56 ++++++++++++++++++++++++++-
 patchwork/templates/patchwork/patch-list.html | 12 ++++++
 2 files changed, 66 insertions(+), 2 deletions(-)

diff --git a/patchwork/filters.py b/patchwork/filters.py
index fca9008..6d8ed71 100644
--- a/patchwork/filters.py
+++ b/patchwork/filters.py
@@ -25,7 +25,9 @@ from django.utils.safestring import mark_safe
 from django.utils import six
 from django.utils.six.moves.urllib.parse import quote
 
-from patchwork.models import Person, State
+from patchwork.models import Person
+from patchwork.models import SeriesRevision
+from patchwork.models import State
 
 
 class Filter(object):
@@ -82,6 +84,55 @@ class Filter(object):
         return '%s: %s' % (self.name, self.kwargs())
 
 
+class SeriesFilter(Filter):
+    param = 'series'
+    name = 'Series'
+
+    def __init__(self, filters):
+        super(SeriesFilter, self).__init__(filters)
+        self.series = None
+
+    def _set_key(self, key):
+        self.series = None
+        series_id = None
+
+        key = key.strip()
+        if not key:
+            return
+
+        try:
+            series_id = int(key)
+        except ValueError:
+            pass
+        except Exception:
+            return
+
+        if not series_id:
+            return
+
+        self.series = SeriesRevision.objects.get(id=series_id)
+        self.applied = True
+
+    def kwargs(self):
+        if self.series:
+            return {'series_revision': self.series}
+        return {}
+
+    def condition(self):
+        if self.series:
+            return self.series.name
+        return ''
+
+    def _form(self):
+        return mark_safe(('<input type="text" name="series" ' +
+                          'id="series_input" class="form-control">'))
+
+    def key(self):
+        if self.series:
+            return self.series.id
+        return
+
+
 class SubmitterFilter(Filter):
     param = 'submitter'
 
@@ -395,7 +446,8 @@ class DelegateFilter(Filter):
             self.forced = True
 
 
-filterclasses = [SubmitterFilter,
+filterclasses = [SeriesFilter,
+                 SubmitterFilter,
                  StateFilter,
                  SearchFilter,
                  ArchiveFilter,
diff --git a/patchwork/templates/patchwork/patch-list.html b/patchwork/templates/patchwork/patch-list.html
index b7648d3..6ba3998 100644
--- a/patchwork/templates/patchwork/patch-list.html
+++ b/patchwork/templates/patchwork/patch-list.html
@@ -83,6 +83,11 @@ $(document).ready(function() {
    </th>
 
    <th>
+    <!-- TODO(stephenfin) Make this column sortable -->
+    <span class="colinactive">Series</span>
+   </th>
+
+   <th>
     {% project_tags %}
    </th>
 
@@ -176,6 +181,13 @@ $(document).ready(function() {
      {{ patch.name|default:"[no subject]"|truncatechars:100 }}
     </a>
    </td>
+   <td>
+    {% if patch.series %}
+    <a href="?series={{patch.series.id}}">
+     {{ patch.series.display_name|truncatechars:100 }}
+    </a>
+    {% endif %}
+   </td>
    <td class="text-nowrap">{{ patch|patch_tags }}</td>
    <td class="text-nowrap">{{ patch|patch_checks }}</td>
    <td class="text-nowrap">{{ patch.date|date:"Y-m-d" }}</td>
-- 
2.7.4



More information about the Patchwork mailing list