From d21de73592062bce687e78e2dc4d0f415f42b3cf Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Fri, 27 Aug 2010 17:24:08 -0500 Subject: Add last updated column to package groups view Just another annotation to the queryset to get this data, and a little more manipulation in the group data function. This will help when adding a sitemap in a subsequent commit. Signed-off-by: Dan McGee --- packages/views.py | 12 ++++++++---- templates/packages/groups.html | 2 ++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/packages/views.py b/packages/views.py index 3caf5ec..ae31f15 100644 --- a/packages/views.py +++ b/packages/views.py @@ -11,7 +11,7 @@ from django.contrib.admin.widgets import AdminDateWidget from django.views.decorators.cache import never_cache from django.views.decorators.vary import vary_on_headers from django.views.generic import list_detail -from django.db.models import Count, Q +from django.db.models import Count, Max, Q from datetime import datetime from operator import itemgetter @@ -88,13 +88,14 @@ def details(request, name='', repo='', arch=''): def get_group_information(): raw_groups = PackageGroup.objects.values_list( 'name', 'pkg__arch__name').order_by('name').annotate( - cnt=Count('pkg')) + cnt=Count('pkg'), last_update=Max('pkg__last_update')) # now for post_processing. we need to seperate things out and add # the count in for 'any' to all of the other architectures. group_mapping = {} for g in raw_groups: arch_groups = group_mapping.setdefault(g[1], {}) - arch_groups[g[0]] = {'name': g[0], 'arch': g[1], 'count': g[2]} + arch_groups[g[0]] = {'name': g[0], 'arch': g[1], + 'count': g[2], 'last_update': g[3]} # we want to promote the count of 'any' packages in groups to the # other architectures, and also add any 'any'-only groups @@ -104,7 +105,10 @@ def get_group_information(): for arch, arch_groups in group_mapping.iteritems(): for g in any_groups.itervalues(): if g['name'] in arch_groups: - arch_groups[g['name']]['count'] += g['count'] + found = arch_groups[g['name']] + found['count'] += g['count'] + if g['last_update'] > found['last_update']: + found['last_update'] = g['last_update'] else: new_g = g.copy() # override the arch to not be 'any' diff --git a/templates/packages/groups.html b/templates/packages/groups.html index 4bf12ac..bb475b1 100644 --- a/templates/packages/groups.html +++ b/templates/packages/groups.html @@ -11,6 +11,7 @@ Arch Group Name Package Count + Last Updated @@ -20,6 +21,7 @@ {{ grp.name }} {{ grp.count }} Packages + {{ grp.last_update|date:"Y-m-d" }} {% endfor %} -- cgit v1.2.3-24-g4f1b