Skip to content

Commit

Permalink
feat(category-filter): add category filter for proposal review table
Browse files Browse the repository at this point in the history
  • Loading branch information
iknowright committed Sep 7, 2023
1 parent 6e04f1a commit bad1dec
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 7 deletions.
27 changes: 23 additions & 4 deletions src/reviews/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand All @@ -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
Expand All @@ -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 = (
Expand Down Expand Up @@ -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):
Expand Down
20 changes: 19 additions & 1 deletion src/templates/default/reviews/_includes/proposal_table.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,21 @@
<i class="fa fa-sort-desc fa-lg"></i>
</a>
</th>
<th width="1%" class="hidden-md hidden-sm hidden-xs">
<select onchange="javascript:location.href = this.value;">
{% if not category %}
<option value="?order=count">ALL</option>
{% else %}
<option value="?order=count&category={{ category }}">{{ category }}</option>
<option value="?order=count">ALL</option>
{% endif %}
{% for category_option in category_options %}
{% if category != category_option %}
<option value="?order=count&category={{ category_option }}">{{ category_option }}</option>
{% endif %}
{% endfor %}
</select>
</th>
{% if verdict %}
<th width="1%">{% trans 'Decision' %}</th>
{% endif %}
Expand All @@ -41,6 +56,7 @@
</thead>
<tbody>
{% for proposal in proposals %}
{% if proposal.category == category or not category %}
<tr>
{% if proposal.accepted == None %}
<td>{{ proposal.review__count }}</td>
Expand All @@ -49,8 +65,9 @@
<div {% if proposal.review__count > reviews_enough %} class="grayed-out" {% endif %} >{{ proposal.title }}</div>
</td>
<td class="hidden-md hidden-sm hidden-xs">{{ proposal.get_language_display }}</td>
<td class="hidden-md hidden-sm hidden-xs">{{ proposal.category }}</td>
{% if proposal.accepted != None %}
<td class="hidden-md hidden-sm hidden-xs">{{ proposal.get_accepted_display }}</td>
<td class="hidden-md hidden-sm hidden-xs">{{ proposal.get_accepted_display }}</td>
{% endif %}
<td>
{% if proposal.accepted == None %}
Expand All @@ -62,6 +79,7 @@
{% endif %}
</td>
</tr>
{% endif %}
{% endfor %}
</tbody>
</table>
4 changes: 2 additions & 2 deletions src/templates/default/reviews/talk_proposal_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ <h4>{% trans 'Personal Review Stats' %}</h4>
</div>
<!-- Nav tabs -->
<ul class="nav nav-tabs reviews-tabs js-hash-tabs" role="tablist">
<li role="presentation" class="active"><a href="#unreviewed" aria-controls="unreviewed" role="tab" data-toggle="tab">{% trans 'Unreviewed Talk Proposals' %} ({{ object_list|length }})</a></li>
<li role="presentation" class="active"><a href="#unreviewed" aria-controls="unreviewed" role="tab" data-toggle="tab">{% trans 'Unreviewed Talk Proposals' %} ({{ filtered_count }} of {{ object_list|length }})</a></li>
<li role="presentation"><a href="#reviewed" aria-controls="reviewed" role="tab" data-toggle="tab">{% trans 'Reviewed Talk Proposals' %} ({{ total_reviewed_amount }})</a></li>
{% if review_stage == 2 and proposals_with_verdict %}
<li role="presentation"><a href="#verdicted" aria-controls="verdicted" role="tab" data-toggle="tab">{% trans 'Talk Proposals With Decision' %} ({{ proposals_with_verdict|length }})</a></li>
Expand All @@ -59,7 +59,7 @@ <h4>{% trans 'Personal Review Stats' %}</h4>
<div role="tabpanel" class="tab-pane active" id="unreviewed">
<div class="talk-proposals proposals">
{% if object_list %}
{% include 'reviews/_includes/proposal_table.html' with proposals=object_list verdict=False %}
{% include 'reviews/_includes/proposal_table.html' with proposals=object_list verdict=False category_options=category_options %}
{% else %}
<p>{% blocktrans %}You have reviewed all talk proposals.{% endblocktrans %}</p>
{% endif %}
Expand Down

0 comments on commit bad1dec

Please sign in to comment.