[PATCH v7 7/8] templates: Integrate series support
Stephen Finucane
stephen at that.guru
Sun Oct 30 00:13:39 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>
Reviewed-by: Andy Doan <andy.doan at linaro.org>
Tested-by: Russell Currey <ruscur at russell.cc>
---
v7:
- Reference 'Series' instead of 'SeriesRevision'
- Remove unnecessary 'Exception' handler
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 | 49 +++++++++++++++++++++++++--
patchwork/templates/patchwork/patch-list.html | 13 +++++++
patchwork/views/__init__.py | 4 +--
3 files changed, 62 insertions(+), 4 deletions(-)
diff --git a/patchwork/filters.py b/patchwork/filters.py
index ea832b7..bc8ca41 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 Series
+from patchwork.models import State
class Filter(object):
@@ -82,6 +84,48 @@ 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
+
+ key = key.strip()
+ if not key:
+ return
+
+ try:
+ self.series = Series.objects.get(id=int(key))
+ except (ValueError, Series.DoesNotExist):
+ return
+
+ self.applied = True
+
+ def kwargs(self):
+ if self.series:
+ return {'series': 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'
@@ -391,7 +435,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..4b979ac 100644
--- a/patchwork/templates/patchwork/patch-list.html
+++ b/patchwork/templates/patchwork/patch-list.html
@@ -83,6 +83,10 @@ $(document).ready(function() {
</th>
<th>
+ <span class="colinactive">Series</span>
+ </th>
+
+ <th>
{% project_tags %}
</th>
@@ -176,6 +180,15 @@ $(document).ready(function() {
{{ patch.name|default:"[no subject]"|truncatechars:100 }}
</a>
</td>
+ <td>
+ {% with patch.series.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..a29da83 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
+ patches = patches.prefetch_related('check_set', 'series')
paginator = Paginator(request, patches)
--
2.7.4
More information about the Patchwork
mailing list