From a4e5f3bbbffd7affb74f48dfc450a4b63c9ff2d0 Mon Sep 17 00:00:00 2001 From: olivier <> Date: Tue, 16 Feb 2010 21:23:12 +0000 Subject: [PATCH] fix and improve the continent-specific geo navigator list --- telemeta/models/query.py | 37 +------------------ .../telemeta_default/geo_countries.html | 34 +++++++++++++---- telemeta/web/base.py | 7 +++- 3 files changed, 34 insertions(+), 44 deletions(-) diff --git a/telemeta/models/query.py b/telemeta/models/query.py index 23cb5594..fb922ca2 100644 --- a/telemeta/models/query.py +++ b/telemeta/models/query.py @@ -122,6 +122,8 @@ class MediaItemQuerySet(CoreQuerySet): ordered.append({'continent': c, 'countries': grouped[c]}) countries = ordered + else: + countries.sort(self.__name_cmp) return countries @@ -326,41 +328,6 @@ class MediaCollectionManager(CoreManager): def __name_cmp(obj1, obj2): return unaccent_icmp(obj1.name, obj2.name) - def stat_continents(self, only_continent=None): - "Return the number of collections by continents and countries as a tree" - - from telemeta.models.media import MediaItem - from telemeta.models.location import Location - - countries = [] - for lid in MediaItem.objects.filter(location__isnull=False).values_list('location', flat=True).distinct(): - location = Location.objects.get(pk=lid) - if not only_continent or (only_continent in location.continents()): - for l in location.countries(): - if not l in countries: - countries.append(l) - - stat = {} - - for country in countries: - count = country.collections().count() - for continent in country.continents(): - if not stat.has_key(continent): - stat[continent] = {} - - stat[continent][country] = count - - keys1 = stat.keys() - keys1.sort(self.__name_cmp) - ordered = [] - for c in keys1: - keys2 = stat[c].keys() - keys2.sort(self.__name_cmp) - sub = [{'location': d, 'count': stat[c][d]} for d in keys2] - ordered.append({'location': c, 'countries': sub}) - - return ordered - class LocationQuerySet(CoreQuerySet): __flatname_map = None diff --git a/telemeta/templates/telemeta_default/geo_countries.html b/telemeta/templates/telemeta_default/geo_countries.html index a23e3e15..65ec1356 100644 --- a/telemeta/templates/telemeta_default/geo_countries.html +++ b/telemeta/templates/telemeta_default/geo_countries.html @@ -2,15 +2,35 @@ {% load telemeta_utils %} {% load i18n %} -{% block head_title %}{{ continent.location.name }} - {% trans "Geographic Navigator" %} - {{ block.super }}{% endblock %} +{% block head_title %}{{ continent }} - {% trans "Geographic Navigator" %} - {{ block.super }}{% endblock %} {% block content %}
{% trans "Country" %} | +{% trans "Number of collections" %} | +{% trans "Number of items" %} | +
---|---|---|
{{ country }} | ++ {% with country.collections.count as num %} + + {% blocktrans count num as counter %}1 collection{% plural %}{{ counter }} collections{% endblocktrans %} + + {% endwith %} + | ++ {% with country.items.count as num %} + + {% blocktrans count num as counter %}1 item{% plural %}{{ counter }} items {% endblocktrans %} + + {% endwith %} + | +