filters: re-add the possibility of filtering undelegated patches

Mauro Carvalho Chehab mchehab at infradead.org
Mon Jun 3 03:40:21 AEST 2019


The filters.py redesign that happened for patchwork 1.1 removed
a functionality that we use a lot: to filter patches that weren't
delegated to anyone.

Also, it is a way harder to find someone to delegate with a free
text input. Use, instead a combo-box just like before.

Signed-off-by: Mauro Carvalho Chehab <mchehab at osg.samsung.com>

---

LinuxTV was using some pre-version 1.0 patchwork instance since
last week. Migrating was not easy, due to the delegation patches we
developed for 1.x, that caused the migration scripts to fail.

On Friday, we finally migrated to the latest stable version:

	https://patchwork.linuxtv.org

After the migration, we noticed that one feature that we used a
lot got removed from patchwork: the filter was not allowing anymore
to filter not-delegated patches.

On media, we receive a large amount of patches per week. Just after
the migration, we received ~30 patches, and that's because it is
a weekend!

In order to handle such high volume, we have several sub-maintainers,
each one responsible for one part of the subsystem. While we do have
delegation rules on patchwork, we still do manual delegation. So,
being able to see what patches are not on someone's queue is very
important to us.

This patch restores such feature to patchwork. As a plus, it now
shows a combo-box with just the names of people that maintain
projects, instead of a free-text input that would otherwise seek
the entire user's database.

diff --git a/patchwork/filters.py b/patchwork/filters.py
index f6e483947b24..167f219810aa 100644
--- a/patchwork/filters.py
+++ b/patchwork/filters.py
@@ -375,6 +375,7 @@ class ArchiveFilter(Filter):
 
 class DelegateFilter(Filter):
     param = 'delegate'
+    no_delegate_str = 'Nobody'
     AnyDelegate = 1
 
     def __init__(self, filters):
@@ -391,6 +392,11 @@ class DelegateFilter(Filter):
         if not key:
             return
 
+        if key == self.no_delegate_str:
+            self.delegate_match = key
+            self.applied = True
+            return
+
         try:
             self.delegate = User.objects.get(id=int(key))
         except (ValueError, User.DoesNotExist):
@@ -410,6 +416,9 @@ class DelegateFilter(Filter):
         if self.delegate:
             return {'delegate': self.delegate}
 
+        if self.delegate_match == self.no_delegate_str:
+            return {'delegate__username__isnull': True}
+
         if self.delegate_match:
             return {'delegate__username__icontains': self.delegate_match}
         return {}
@@ -422,8 +431,33 @@ class DelegateFilter(Filter):
         return ''
 
     def _form(self):
-        return mark_safe('<input type="text" name="delegate" '
-                         'id="delegate_input" class="form-control">')
+        delegates = User.objects.filter(profile__maintainer_projects__isnull = False)
+
+        str = '<select name="delegate">'
+
+        selected = ''
+        if not self.applied:
+            selected = 'selected'
+
+        str += '<option %s value="">------</option>' % selected
+
+        selected = ''
+        if self.applied and self.delegate is None:
+            selected = 'selected'
+
+        str += '<option %s value="%s">%s</option>' % \
+                (selected, self.no_delegate_str, self.no_delegate_str)
+
+        for d in delegates:
+            selected = ''
+            if d == self.delegate:
+                selected = ' selected'
+
+            str += '<option %s value="%s">%s</option>' % (selected,
+                    d.id, d.username)
+        str += '</select>'
+
+        return mark_safe(str)
 
     def key(self):
         if self.delegate:


More information about the Patchwork mailing list