Skip to content

Commit

Permalink
[orga] Allow to sort by number of reviews on the review page
Browse files Browse the repository at this point in the history
Closes #457
  • Loading branch information
rixx committed Feb 22, 2019
1 parent 7b2491d commit 8884957
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 11 deletions.
1 change: 1 addition & 0 deletions doc/changelog.rst
Expand Up @@ -3,6 +3,7 @@
Release Notes
=============

- :feature:`457` You can now order submissions by the number of reviews they have received on the review page.
- :feature:`566` The Reply-To field now permits multiple email addresses.
- :bug:`579` When organisers changed the event timeframe, already submitted availabilites would have to be changed upon new submission.
- :feature:`577` You can now decide if text lengths should be counted in words or in characters when restricting how long they should be.
Expand Down
8 changes: 5 additions & 3 deletions src/pretalx/common/mixins/views.py
Expand Up @@ -70,9 +70,11 @@ class Sortable:
sortable_fields = []

def sort_queryset(self, qs):
sort_key = self.request.GET.get('sort') or getattr(
self, 'default_sort_field', ''
)
sort_key = self.request.GET.get('sort')
if not sort_key or sort_key == 'default':
sort_key = getattr(
self, 'default_sort_field', ''
)
if sort_key:
plain_key = sort_key[1:] if sort_key.startswith('-') else sort_key
reverse = not (plain_key == sort_key)
Expand Down
12 changes: 10 additions & 2 deletions src/pretalx/orga/templates/orga/review/dashboard.html
Expand Up @@ -3,6 +3,7 @@
{% load i18n %}
{% load review_score %}
{% load rules %}
{% load url_replace %}

{% block content %}
{% has_perm 'orga.change_settings' request.user request.event as can_see_settings %}
Expand Down Expand Up @@ -89,8 +90,15 @@ <h1>{% trans "Bravo!!" %}</h1>
<table class="table table-sm review-table table-hover table-responsive-md">
<thead>
<tr>
<th>{% trans "Score" %} <i class="fa fa-caret-down"></i></th>
<th>{% trans "Reviews" %}</th>
<th>
{% trans "Score" %}
<a href="?{% url_replace request 'sort' 'default' %}"><i class="fa fa-caret-down"></i></a>
</th>
<th>
{% trans "Reviews" %}
<a href="?{% url_replace request 'sort' '-count' %}"><i class="fa fa-caret-down"></i></a>
<a href="?{% url_replace request 'sort' 'count' %}"><i class="fa fa-caret-up"></i></a>
</th>
<th>{% trans "Title" %}</th>
{% if can_view_speakers %}<th>{% trans "Speakers" %}</th>{% endif %}
<th>{% trans "Type" %}</th>
Expand Down
16 changes: 10 additions & 6 deletions src/pretalx/orga/views/review.py
Expand Up @@ -53,9 +53,8 @@ def get_queryset(self):
]
)
queryset = self.filter_queryset(queryset)
return (
queryset.order_by('review_id')
.annotate(has_override=models.Exists(overridden_reviews))
queryset = queryset.order_by('review_id')\
.annotate(has_override=models.Exists(overridden_reviews))\
.annotate(
avg_score=models.Case(
models.When(
Expand All @@ -64,9 +63,14 @@ def get_queryset(self):
),
default=models.Avg('reviews__score'),
)
)
.order_by('-state', '-avg_score', 'code')
)
).annotate(review_count=models.Count('reviews'))
ordering = self.request.GET.get('sort', 'default')
if ordering == 'default':
return queryset.order_by('-state', '-avg_score', 'code')
if ordering == 'count':
return queryset.order_by('review_count')
if ordering == '-count':
return queryset.order_by('-review_count')

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
Expand Down

0 comments on commit 8884957

Please sign in to comment.