Skip to content

Commit b0b7e5d

Browse files
mchehabstephenfin
authored andcommitted
filters: re-add the possibility of filtering undelegated patches
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 <[email protected]> Signed-off-by: Stephen Finucane <[email protected]> Fixes: f439f54 ("Add delegate filter autocomplete support") Closes: #60 [stephenfin: Rework release note and fix some style issues] (cherry picked from commit e99490c)
1 parent 9f24264 commit b0b7e5d

File tree

3 files changed

+42
-40
lines changed

3 files changed

+42
-40
lines changed

patchwork/filters.py

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,7 @@ def url_without_me(self):
375375

376376
class DelegateFilter(Filter):
377377
param = 'delegate'
378+
no_delegate_str = 'Nobody'
378379
AnyDelegate = 1
379380

380381
def __init__(self, filters):
@@ -391,6 +392,11 @@ def _set_key(self, key):
391392
if not key:
392393
return
393394

395+
if key == self.no_delegate_str:
396+
self.delegate_match = key
397+
self.applied = True
398+
return
399+
394400
try:
395401
self.delegate = User.objects.get(id=int(key))
396402
except (ValueError, User.DoesNotExist):
@@ -410,6 +416,9 @@ def kwargs(self):
410416
if self.delegate:
411417
return {'delegate': self.delegate}
412418

419+
if self.delegate_match == self.no_delegate_str:
420+
return {'delegate__username__isnull': True}
421+
413422
if self.delegate_match:
414423
return {'delegate__username__icontains': self.delegate_match}
415424
return {}
@@ -422,8 +431,31 @@ def condition(self):
422431
return ''
423432

424433
def _form(self):
425-
return mark_safe('<input type="text" name="delegate" '
426-
'id="delegate_input" class="form-control">')
434+
delegates = User.objects.filter(
435+
profile__maintainer_projects__isnull=False)
436+
437+
out = '<select name="delegate" class="form-control">'
438+
439+
selected = ''
440+
if not self.applied:
441+
selected = 'selected'
442+
out += '<option %s value="">------</option>' % selected
443+
444+
selected = ''
445+
if self.applied and self.delegate is None:
446+
selected = 'selected'
447+
out += '<option %s value="%s">%s</option>' % (
448+
selected, self.no_delegate_str, self.no_delegate_str)
449+
450+
for delegate in delegates:
451+
selected = ''
452+
if delegate == self.delegate:
453+
selected = ' selected'
454+
455+
out += '<option %s value="%s">%s</option>' % (
456+
selected, delegate.id, delegate.username)
457+
out += '</select>'
458+
return mark_safe(out)
427459

428460
def key(self):
429461
if self.delegate:

patchwork/templates/patchwork/filters.html

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -76,44 +76,6 @@
7676
});
7777
}
7878
});
79-
80-
$('#delegate_input').selectize({
81-
plugins: ['enter_key_submit'],
82-
maxItems: 1,
83-
persist: false,
84-
onInitialize: function() {
85-
this.on('submit', function() {
86-
if (!this.items.length)
87-
this.$input.val(this.lastValue);
88-
this.$input.closest('form').submit();
89-
}, this);
90-
},
91-
{% if "delegate" in filters.applied_filters %}
92-
{% with delegate_filter=filters.applied_filters.delegate %}
93-
options: [
94-
{
95-
value: "{{ delegate_filter.key }}",
96-
text: "{{ delegate_filter.condition }}",
97-
},
98-
],
99-
items: ["{{ delegate_filter.key }}"],
100-
{% endwith %}
101-
{% endif %}
102-
load: function(query, callback) {
103-
req = $.ajax({
104-
url: "{% url 'api-delegates' %}",
105-
data: {q: query, l: 10},
106-
error: function() {
107-
callback();
108-
},
109-
success: function(res) {
110-
callback($.map(res, function (obj) {
111-
return {value: obj.pk, text: obj.name};
112-
}));
113-
}
114-
});
115-
}
116-
});
11779
});
11880
</script>
11981

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
fixes:
3+
- |
4+
In the past, Patchwork used to support filtering patches that weren't
5+
delegated to anyone. This feature was removed in v1.1.0, as part of a patch
6+
designed to support delegation to anyone. However, that feature didn't scale
7+
and was later removed. The ability to delegate to anyone is now itself
8+
re-introduced.

0 commit comments

Comments
 (0)