Skip to content

Commit e7fba3e

Browse files
committed
Allow filtering by multiple tags at once
1 parent e8ee2bb commit e7fba3e

File tree

2 files changed

+10
-16
lines changed

2 files changed

+10
-16
lines changed

pgcommitfest/commitfest/forms.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class CommitFestFilterForm(forms.Form):
1919
text = forms.CharField(max_length=50, required=False)
2020
status = forms.ChoiceField(required=False)
2121
targetversion = forms.ChoiceField(required=False)
22-
tag = forms.ChoiceField(required=False, label="Tag (type to search)")
22+
tag = forms.MultipleChoiceField(required=False, label="Tag (type to search)")
2323
author = forms.ChoiceField(required=False, label="Author (type to search)")
2424
reviewer = forms.ChoiceField(required=False, label="Reviewer (type to search)")
2525
sortkey = forms.IntegerField(required=False)
@@ -61,9 +61,7 @@ def __init__(self, data, *args, **kwargs):
6161
)
6262
self.fields["author"].choices = userchoices
6363
self.fields["reviewer"].choices = userchoices
64-
self.fields["tag"].choices = [(-1, "* All"), (-2, "* None")] + list(
65-
Tag.objects.all().values_list("id", "name")
66-
)
64+
self.fields["tag"].choices = list(Tag.objects.all().values_list("id", "name"))
6765

6866
for f in (
6967
"status",

pgcommitfest/commitfest/views.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -285,20 +285,16 @@ def patchlist(request, cf, personalized=False):
285285
# int() failed, ignore
286286
pass
287287

288-
if request.GET.get("tag", "-1") != "-1":
289-
if request.GET["tag"] == "-2":
290-
whereclauses.append(
291-
"NOT EXISTS (SELECT 1 FROM commitfest_patch_tags tags WHERE tags.patch_id=p.id)"
292-
)
293-
else:
294-
try:
295-
whereparams["tag"] = int(request.GET["tag"])
288+
if request.GET.getlist("tag") != []:
289+
try:
290+
tag_ids = [int(t) for t in request.GET.getlist("tag")]
291+
for tag_id in tag_ids:
296292
whereclauses.append(
297-
"EXISTS (SELECT 1 FROM commitfest_patch_tags tags WHERE tags.patch_id=p.id AND tags.tag_id=%(tag)s)"
293+
f"EXISTS (SELECT 1 FROM commitfest_patch_tags tags WHERE tags.patch_id=p.id AND tags.tag_id={tag_id})"
298294
)
299-
except ValueError:
300-
# int() failed -- so just ignore this filter
301-
pass
295+
except ValueError:
296+
# int() failed -- so just ignore this filter
297+
pass
302298

303299
if request.GET.get("author", "-1") != "-1":
304300
if request.GET["author"] == "-2":

0 commit comments

Comments
 (0)