[PATCH v6 7/8] templates: Integrate series support
Stephen Finucane
stephen at that.guru
Sun Oct 16 23:50:53 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>
---
v5:
- Don't use the 'Patch.series' property, which results in a new query
each time
v4:
- Update to use newly added Series.name field
---
patchwork/filters.py | 56 ++++++++++++++++++++++++++-
patchwork/templates/patchwork/patch-list.html | 14 +++++++
patchwork/views/__init__.py | 4 +-
3 files changed, 70 insertions(+), 4 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 937a609..96e7101 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,15 @@ $(document).ready(function() {
{{ patch.name|default:"[no subject]"|truncatechars:100 }}
</a>
</td>
+ <td>
+ {% with patch.series_revisions.all.0 as series %}
+ {% if series %}
+ <a href="?series={{series.id}}">
+ {{ series|truncatechars:100 }}
+ </a>
+ {% endif %}
+ {% endwith %}
+ </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>
diff --git a/patchwork/views/__init__.py b/patchwork/views/__init__.py
index 8b5e881..1559efb 100644
--- a/patchwork/views/__init__.py
+++ b/patchwork/views/__init__.py
@@ -297,8 +297,8 @@ def generic_list(request, project, view, view_args=None, filter_settings=None,
# rendering the list template
patches = patches.select_related('state', 'submitter', 'delegate')
- # we also need checks
- patches = patches.prefetch_related('check_set')
+ # we also need checks and series revisions
+ patches = patches.prefetch_related('check_set', 'series_revisions')
paginator = Paginator(request, patches)
--
2.7.4
More information about the Patchwork
mailing list