Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feat] add category filter on review page #1145

Merged
merged 2 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 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,8 +148,10 @@ 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),
})
return context

Expand Down
36 changes: 27 additions & 9 deletions src/templates/default/reviews/_includes/proposal_table.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
<tr>
{% if not verdict %}
<th width="1%">
<a {% if ordering == 'review__count' %}class="active asc" href="?order=-count"
{% elif ordering == '-review__count' %}class="active desc" href="?order=count"
{% else %}href="?order=count"{% endif %}>
<a {% if ordering == 'review__count' %}class="active asc" href="?order=-count&category={{ category }}"
{% elif ordering == '-review__count' %}class="active desc" href="?order=count&category={{ category }}"
{% else %}href="?order=count&category={{ category }}"{% endif %}>
{% trans 'Reviewed' %}
<i class="fa fa-sort fa-lg"></i>
<i class="fa fa-sort-asc fa-lg"></i>
Expand All @@ -15,24 +15,39 @@
</th>
{% endif %}
<th class="proposal-title">
<a {% if ordering == 'title' %}class="active asc" href="?order=-title"
{% elif ordering == '-title' %}class="active desc" href="?order=title"{% else %}href="?order=title"{% endif %}>
<a {% if ordering == 'title' %}class="active asc" href="?order=-title&category={{ category }}"
{% elif ordering == '-title' %}class="active desc" href="?order=title&category={{ category }}"{% else %}href="?order=title&category={{ category }}"{% endif %}>
{% trans 'Title' %}
<i class="fa fa-sort fa-lg"></i>
<i class="fa fa-sort-asc fa-lg"></i>
<i class="fa fa-sort-desc fa-lg"></i>
</a>
</th>
<th width="1%" class="hidden-md hidden-sm hidden-xs">
<a {% if ordering == 'language' %}class="active asc" href="?order=-lang"
{% elif ordering == '-language' %}class="active desc" href="?order=lang"
{% else %}href="?order=lang"{% endif %}>
<a {% if ordering == 'language' %}class="active asc" href="?order=-lang&category={{ category }}"
{% elif ordering == '-language' %}class="active desc" href="?order=lang&category={{ category }}"
{% else %}href="?order=lang&category={{ category }}"{% endif %}>
{% trans 'Lang' %}
<i class="fa fa-sort fa-lg"></i>
<i class="fa fa-sort-asc fa-lg"></i>
<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 = `?order=${new URLSearchParams(location.search).get('order')}${this.value}`;">
{% if not category %}
<option value="">ALL</option>
{% else %}
<option value="&category={{ category }}">{{ category }}</option>
<option value="">ALL</option>
{% endif %}
{% for category_option in category_options %}
{% if category != category_option %}
<option value="&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