UI for ordering by latest revision

This commit is contained in:
Karl Hobley 2014-10-08 16:13:55 +01:00
parent 6ecd082958
commit 19cb2c5731
2 changed files with 22 additions and 5 deletions

View file

@ -10,6 +10,7 @@
{% endif %}
<col width="12%" />
<col width="12%" />
<col width="12%" />
<col width="10%" />
<thead>
{% if moving or choosing %}
@ -21,6 +22,7 @@
{% if show_parent %}
<th class="parent">{% trans 'Parent' %}</th>
{% endif %}
<th class="updated">{% trans 'Updated' %}</th>
<th class="type">{% trans 'Type' %}</th>
<th class="status">{% trans 'Status' %}</th>
<th></th>
@ -96,6 +98,7 @@
</ul>
{% endif %}
</td>
<td class="updated" valign="bottom"><div class="human-readable-date" title="{{ parent_page.latest_revision_created_at|date:"d M Y H:i" }}">{{ parent_page.latest_revision_created_at|timesince }}</div></td>
<td class="type" valign="bottom">{{ parent_page.content_type.model_class.get_verbose_name }}</td>
<td class="status" valign="bottom">
{% if not choosing and not moving and parent_page.live and not parent_page.is_root and 'view_live' not in hide_actions|default:'' %}
@ -129,8 +132,17 @@
{% endif %}
</th>
{% if show_parent %}
<th class="parent">Parent</th>
<th class="parent">{% trans 'Parent' %}</th>
{% endif %}
<th class="updated">
{% if sortable %}
<a href="{% url 'wagtailadmin_explore' parent_page.id %}?ordering={% if ordering == "latest_revision_created_at" %}-{% endif %}latest_revision_created_at" class="icon icon-arrow-{% if ordering == "-latest_revision_created_at" %}up-after{% else %}down-after{% endif %} {% if ordering == "latest_revision_created_at" or ordering == "-latest_revision_created_at" %}teal {% endif %}">
{% trans 'Updated' %}
</a>
{% else %}
{% trans 'Updated' %}
{% endif %}
</th>
<th class="type">
{% if sortable %}
<a href="{% url 'wagtailadmin_explore' parent_page.id %}?ordering={% if ordering == "content_type" %}-{% endif %}content_type" class="icon icon-arrow-{% if ordering == "-content_type" %}up-after{% else %}down-after{% endif %} {% if ordering == "content_type" or ordering == "-content_type" %}teal {% endif %}">
@ -230,6 +242,7 @@
</td>
{% endwith %}
{% endif %}
<td class="updated" valign="top"><div class="human-readable-date" title="{{ page.latest_revision_created_at|date:"d M Y H:i" }}">{{ page.latest_revision_created_at|timesince }}</div></td>
<td class="type" valign="top">{{ page.content_type.model_class.get_verbose_name }}</td>
<td class="status" valign="top">
{% if not choosing and not moving and page.live and 'view_live' not in hide_actions|default:'' %}

View file

@ -12,6 +12,7 @@ from django.utils.translation import ugettext as _
from django.utils.http import is_safe_url
from django.views.decorators.http import require_GET, require_POST
from django.views.decorators.vary import vary_on_headers
from django.db.models import Count
from wagtail.wagtailadmin.edit_handlers import TabbedInterface, ObjectList
from wagtail.wagtailadmin.forms import SearchForm, CopyForm
@ -38,13 +39,16 @@ def index(request, parent_page_id=None):
pages = parent_page.get_children().prefetch_related('content_type')
# Get page ordering
ordering = request.GET.get('ordering', 'title')
if ordering not in ['title', '-title', 'content_type', '-content_type', 'live', '-live', 'ord']:
ordering = 'title'
ordering = request.GET.get('ordering', '-latest_revision_created_at')
if ordering not in ['title', '-title', 'content_type', '-content_type', 'live', '-live', 'latest_revision_created_at', '-latest_revision_created_at', 'ord']:
ordering = '-latest_revision_created_at'
# Pagination
if ordering != 'ord':
pages = pages.order_by(ordering)
ordering_no_minus = ordering
if ordering_no_minus.startswith('-'):
ordering_no_minus = ordering[1:]
pages = pages.order_by(ordering).annotate(null_position=Count(ordering_no_minus)).order_by('-null_position', ordering)
p = request.GET.get('p', 1)
paginator = Paginator(pages, 50)