From f92f87ce60e4f43a022a3cd3dec4fac4747adba7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89lie=20Bouttier?= Date: Wed, 3 Dec 2014 01:11:21 +0100 Subject: [PATCH] sort issues by last activity / creation date --- templates/tracker/issue_list.html | 12 ++++++------ tracker/views.py | 19 ++++++++++++++++--- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/templates/tracker/issue_list.html b/templates/tracker/issue_list.html index 1adcc1f..43efe39 100644 --- a/templates/tracker/issue_list.html +++ b/templates/tracker/issue_list.html @@ -61,7 +61,6 @@ {% endif %} - {% comment %}
- {% endcomment %} diff --git a/tracker/views.py b/tracker/views.py index 77212dd..1f501eb 100644 --- a/tracker/views.py +++ b/tracker/views.py @@ -6,6 +6,7 @@ from django.views.decorators.http import require_http_methods from django.conf import settings from django.core.urlresolvers import reverse from django.http import HttpResponse +from django.db.models import Max from tracker.utils import markdown_to_html from tracker.forms import * @@ -202,8 +203,10 @@ def issue_list(request, project): milestones = Milestone.objects.filter(project=project) sort = request.GET.get('sort', '') - if sort: - sort = '&' + sort + sort_type = ['recently-updated', 'least-recently-updated', + 'newest', 'oldest', ''] + if sort not in sort_type: + sort = '' is_open = '' is_close = '' @@ -290,11 +293,21 @@ def issue_list(request, project): is_all_query += ' ' + constraint if issues: - issues = issues.extra(order_by=['-opened_at']) + if sort and sort == 'newest': + issues = issues.extra(order_by=['-opened_at']) + elif sort and sort == 'oldest': + issues = issues.extra(order_by=['opened_at']) + elif sort and sort == 'least-recently-updated': + issues = issues.annotate(last_activity=Max('events__date')).order_by('last_activity') + else: # recently-updated + issues = issues.annotate(last_activity=Max('events__date')).order_by('-last_activity') if is_open == '' and is_close == '': is_all = ' active' + if sort and sort != 'recently-updated': + sort = '&sort=' + sort + c = { 'project': project, 'issues': issues,