Skip to content

Commit

Permalink
Sort page revisions by "last review requested at"
Browse files Browse the repository at this point in the history
  • Loading branch information
mixxorz committed May 20, 2019
1 parent 5413c84 commit 23b81d7
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
22 changes: 20 additions & 2 deletions wagtail_review/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from django.conf import settings
from django.core.exceptions import ValidationError
from django.db import models
from django.db.models import Case, Value, When
from django.template.loader import render_to_string
from django.urls import reverse
from django.utils.functional import cached_property
Expand Down Expand Up @@ -58,8 +59,25 @@ def get_pages_with_reviews_for_user(cls, user):
Return a queryset of pages which have reviews, for which the user has edit permission
"""
user_perms = UserPagePermissionsProxy(user)
reviewed_pages = cls.objects.values_list('page_revision__page_id', flat=True).distinct()
return user_perms.editable_pages().filter(pk__in=reviewed_pages)
reviewed_pages = (
cls.objects
.order_by('-created_at')
.values_list('page_revision__page_id', 'created_at')
)
# Annotate datetime when a review was last created for this page
last_review_requested_at = Case(
*[
When(pk=pk, then=Value(created_at))
for pk, created_at in reviewed_pages
],
output_field=models.DateTimeField(),
)
return (
user_perms.editable_pages()
.filter(pk__in=(page[0] for page in reviewed_pages))
.annotate(last_review_requested_at=last_review_requested_at)
.order_by('-last_review_requested_at')
)

class Meta:
abstract = True
Expand Down
4 changes: 4 additions & 0 deletions wagtail_review/templates/wagtail_review/admin/dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<a href="?ordering=page" class="icon icon-arrow-down-after"></a>
{% endif %}
</th>
<th>{% trans "Last review requested at" %}</th>
<th class="status">{% trans "Status" %}</th>
</tr>
</thead>
Expand All @@ -26,6 +27,9 @@ <h2>
<a href="{% url 'wagtail_review_admin:audit_trail' page.id %}">{{ page.get_admin_display_title }}</a>
</h2>
</td>
<td>
{{ page.last_review_requested_at }}
</td>
<td class="status">
{% page_has_open_review page as is_open %}
{% if is_open %}{% trans "Open" %}{% else %}{% trans "Closed" %}{% endif %}
Expand Down
2 changes: 1 addition & 1 deletion wagtail_review/views/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class DashboardView(generic.IndexView):
context_object_name = 'pages'

def get_queryset(self):
return Review.get_pages_with_reviews_for_user(self.request.user).specific()
return Review.get_pages_with_reviews_for_user(self.request.user)


class AuditTrailView(DetailView):
Expand Down

0 comments on commit 23b81d7

Please sign in to comment.