Skip to content

Commit 415c41a

Browse files
committed
Allow filtering by tags
1 parent 180ac89 commit 415c41a

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

pgcommitfest/commitfest/forms.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,21 @@
55
from django.http import Http404
66

77
from .ajax import _archivesAPI
8-
from .models import MailThread, Patch, PatchOnCommitFest, TargetVersion
8+
from .models import MailThread, Patch, PatchOnCommitFest, Tag, TargetVersion
99
from .widgets import ThreadPickWidget
1010

1111

1212
class CommitFestFilterForm(forms.Form):
1313
selectize_fields = {
1414
"author": "/lookups/user",
1515
"reviewer": "/lookups/user",
16+
"tag": None,
1617
}
1718

1819
text = forms.CharField(max_length=50, required=False)
1920
status = forms.ChoiceField(required=False)
2021
targetversion = forms.ChoiceField(required=False)
22+
tag = forms.ChoiceField(required=False, label="Tag (type to search)")
2123
author = forms.ChoiceField(required=False, label="Author (type to search)")
2224
reviewer = forms.ChoiceField(required=False, label="Reviewer (type to search)")
2325
sortkey = forms.IntegerField(required=False)
@@ -59,6 +61,9 @@ def __init__(self, data, *args, **kwargs):
5961
)
6062
self.fields["author"].choices = userchoices
6163
self.fields["reviewer"].choices = userchoices
64+
self.fields["tag"].choices = [(-1, "* All"), (-2, "* None")] + list(
65+
Tag.objects.all().values_list("id", "name")
66+
)
6267

6368
for f in (
6469
"status",

pgcommitfest/commitfest/views.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,21 @@ def patchlist(request, cf, personalized=False):
263263
# int() failed, ignore
264264
pass
265265

266+
if request.GET.get("tag", "-1") != "-1":
267+
if request.GET["tag"] == "-2":
268+
whereclauses.append(
269+
"NOT EXISTS (SELECT 1 FROM commitfest_patch_tags tags WHERE tags.patch_id=p.id)"
270+
)
271+
else:
272+
try:
273+
whereparams["tag"] = int(request.GET["tag"])
274+
whereclauses.append(
275+
"EXISTS (SELECT 1 FROM commitfest_patch_tags tags WHERE tags.patch_id=p.id AND tags.tag_id=%(tag)s)"
276+
)
277+
except ValueError:
278+
# int() failed -- so just ignore this filter
279+
pass
280+
266281
if request.GET.get("author", "-1") != "-1":
267282
if request.GET["author"] == "-2":
268283
whereclauses.append(

0 commit comments

Comments
 (0)