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 Jul 4, 2023
1 parent 6e04f1a commit 6abfbc6
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
16 changes: 12 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,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):
Expand Down Expand Up @@ -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(),
})
Expand Down
19 changes: 18 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,22 @@
<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>
{% endif %}
{% regroup proposals by category as categories %}
{% for category in categories %}
<option value="?order=count&category={{ category.grouper }}">{{ category.grouper }}</option>
{% endfor %}
</select>
{% if category %}
<a href="?order=count">
Show All
</a>
{% endif %}
</th>
{% if verdict %}
<th width="1%">{% trans 'Decision' %}</th>
{% endif %}
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 Down

0 comments on commit 6abfbc6

Please sign in to comment.