From bad1dec61b237dbc0edce865074b5b01307aa603 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 | 27 ++++++++++++++++--- .../reviews/_includes/proposal_table.html | 20 +++++++++++++- .../default/reviews/talk_proposal_list.html | 4 +-- 3 files changed, 44 insertions(+), 7 deletions(-) diff --git a/src/reviews/views.py b/src/reviews/views.py index 5eda7064b..9fd08f261 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,8 +86,23 @@ def get_queryset(self): else: qs = qs.order_by(ordering) self.ordering = ordering + self.category = self.get_category() + return qs + def get_category_metrics(self, context): + count = 0 + categories = set() + for proposal in context["object_list"]: + if proposal.category == self.category: + count += 1 + if proposal.category not in categories: + categories.add(proposal.category) + return { + "category_options": categories, + "filtered_count": count if count else len(context["object_list"]) + } + def get_context_data(self, **kwargs): review_stage = self.reviews_state.reviews_stage verdicted_proposals = ( @@ -132,9 +148,12 @@ 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(), + **self.get_category_metrics(context), }) + print(context) return context def get_stage_1_reviews(self): diff --git a/src/templates/default/reviews/_includes/proposal_table.html b/src/templates/default/reviews/_includes/proposal_table.html index 627a34bd6..49acb05a1 100644 --- a/src/templates/default/reviews/_includes/proposal_table.html +++ b/src/templates/default/reviews/_includes/proposal_table.html @@ -33,6 +33,21 @@ + + + {% if verdict %} {% trans 'Decision' %} {% endif %} @@ -41,6 +56,7 @@ {% for proposal in proposals %} + {% if proposal.category == category or not category %} {% if proposal.accepted == None %} {{ proposal.review__count }} @@ -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 %} @@ -62,6 +79,7 @@ {% endif %} + {% endif %} {% endfor %} diff --git a/src/templates/default/reviews/talk_proposal_list.html b/src/templates/default/reviews/talk_proposal_list.html index 4d65c8393..76741b523 100644 --- a/src/templates/default/reviews/talk_proposal_list.html +++ b/src/templates/default/reviews/talk_proposal_list.html @@ -48,7 +48,7 @@

{% trans 'Personal Review Stats' %}