summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2010-09-09 13:36:41 -0500
committerDan McGee <dan@archlinux.org>2010-09-09 13:36:41 -0500
commiteaa76ae7584d0938db0298714303e2c23b3eacfd (patch)
tree11857ecc060b36b345f4b824b9d55b3cd6872cce
parentffdf7fec992592255ae2f08ba4db3e4962daf279 (diff)
Improve todo list view page
Add total package count and incomplete package count columns. Also reduce the number of total queries by killing the query per row that was happening before. Signed-off-by: Dan McGee <dan@archlinux.org>
-rw-r--r--templates/todolists/list.html13
-rw-r--r--todolists/views.py15
2 files changed, 22 insertions, 6 deletions
diff --git a/templates/todolists/list.html b/templates/todolists/list.html
index 29829caa..2e75bdac 100644
--- a/templates/todolists/list.html
+++ b/templates/todolists/list.html
@@ -20,6 +20,8 @@
<th>Creation Date</th>
<th>Creator</th>
<th>Description</th>
+ <th>Package Count</th>
+ <th>Incomplete Count</th>
<th>Status</th>
</tr>
</thead>
@@ -31,8 +33,10 @@
<td>{{ list.date_added }}</td>
<td>{{ list.creator.get_full_name }}</td>
<td class="wrap">{{ list.description|safe }}</td>
- <td>{% if list.complete %}<span class="complete">Complete</span>
- {% else %}<span class="incomplete">Incomplete</span>{% endif %}</td>
+ <td>{{ list.pkg_count }}</td>
+ <td>{{ list.incomplete_count }}</td>
+ <td>{% ifequal list.incomplete_count 0 %}<span class="complete">Complete</span>
+ {% else %}<span class="incomplete">Incomplete</span>{% endifequal %}</td>
</tr>
{% endfor %}
</tbody>
@@ -42,7 +46,10 @@
<script type="text/javascript" src="/media/jquery.tablesorter.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
- $(".results").tablesorter({widgets: ['zebra'], sortList: [[1,1]]});
+ // I'm not sure why it didn't autodetect digit, but it has to be explicit
+ // http://stackoverflow.com/questions/302749/jquery-tablesorter-problem
+ $(".results").tablesorter({widgets: ['zebra'], sortList: [[1,1]],
+ headers: { 4: { sorter: 'digit' }, 5: { sorter: 'digit' } } });
});
</script>
{% endblock %}
diff --git a/todolists/views.py b/todolists/views.py
index e3663331..25186243 100644
--- a/todolists/views.py
+++ b/todolists/views.py
@@ -4,6 +4,7 @@ from django.http import HttpResponse
from django.core.mail import send_mail
from django.shortcuts import get_object_or_404, redirect
from django.contrib.auth.decorators import login_required, permission_required
+from django.db.models import Count
from django.views.decorators.cache import never_cache
from django.views.generic.create_update import delete_object
from django.views.generic.simple import direct_to_template
@@ -53,10 +54,18 @@ def view(request, listid):
@login_required
@never_cache
def list(request):
- lists = Todolist.objects.select_related('creator').order_by('-date_added')
+ lists = Todolist.objects.select_related('creator').annotate(
+ pkg_count=Count('todolistpkg')).order_by('-date_added')
+ incomplete = Todolist.objects.filter(todolistpkg__complete=False).annotate(
+ Count('todolistpkg')).values_list('id', 'todolistpkg__count')
+
+ # tag each list with an incomplete package count
+ lookup = {}
+ for k, v in incomplete:
+ lookup[k] = v
for l in lists:
- l.complete = TodolistPkg.objects.filter(
- list=l.id,complete=False).count() == 0
+ l.incomplete_count = lookup.get(l.id, 0)
+
return direct_to_template(request, 'todolists/list.html', {'lists': lists})
@permission_required('main.add_todolist')