From 6abfbc696a59026e45575389458ded7f93c0dc5f Mon Sep 17 00:00:00 2001 From: iknowright Date: Tue, 4 Jul 2023 22:03:19 +0800 Subject: [PATCH] feat(category-filter): add category filter for proposal review table --- src/reviews/views.py | 16 ++++++++++++---- .../reviews/_includes/proposal_table.html | 19 ++++++++++++++++++- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/src/reviews/views.py b/src/reviews/views.py index 5eda7064b..fa4cda142 100644 --- a/src/reviews/views.py +++ b/src/reviews/views.py @@ -55,6 +55,10 @@ def get_ordering(self): order_key = self.order_keys.get(params.get('order', '').lower()) return order_key or '?' + def get_category(self): + params = self.request.GET + return params.get('category', '') + def get_queryset(self): user = self.request.user qs = ( @@ -64,10 +68,7 @@ def get_queryset(self): .exclude(review__reviewer=user) .annotate(Count('review')) ) - # params = self.request.GET - # category = params.get('category', '').upper() - # if category: - # proposals = proposals.filter(category=category) + ordering = self.get_ordering() if ordering == '?': # We don't use order_by('?') because it is crazy slow, and instead @@ -85,6 +86,12 @@ def get_queryset(self): else: qs = qs.order_by(ordering) self.ordering = ordering + + category = self.get_category() + if category: + qs = qs.filter(category=category) + self.category = category + return qs def get_context_data(self, **kwargs): @@ -132,6 +139,7 @@ def get_context_data(self, **kwargs): ), 'vote': vote_mapping, 'ordering': self.ordering, + 'category': self.category, 'query_string': self.request.GET.urlencode(), **self.reviews_state._asdict(), }) diff --git a/src/templates/default/reviews/_includes/proposal_table.html b/src/templates/default/reviews/_includes/proposal_table.html index 627a34bd6..adeec9f7e 100644 --- a/src/templates/default/reviews/_includes/proposal_table.html +++ b/src/templates/default/reviews/_includes/proposal_table.html @@ -33,6 +33,22 @@ + + + {% if category %} + + Show All + + {% endif %} + {% if verdict %} {% trans 'Decision' %} {% endif %} @@ -49,8 +65,9 @@
reviews_enough %} class="grayed-out" {% endif %} >{{ proposal.title }}
{{ proposal.get_language_display }} + {{ proposal.category }} {% if proposal.accepted != None %} - {{ proposal.get_accepted_display }} + {{ proposal.get_accepted_display }} {% endif %} {% if proposal.accepted == None %}