]> git.parisson.com Git - telemeta.git/commitdiff
fix and improve the continent-specific geo navigator list
authorolivier <>
Tue, 16 Feb 2010 21:23:12 +0000 (21:23 +0000)
committerolivier <>
Tue, 16 Feb 2010 21:23:12 +0000 (21:23 +0000)
telemeta/models/query.py
telemeta/templates/telemeta_default/geo_countries.html
telemeta/web/base.py

index 23cb55944103caca33de0d3438bd254bffb07d8d..fb922ca2e64d5ee56b73fca2ac1c868c902134b7 100644 (file)
@@ -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
 
index a23e3e1553c54019038d922be7500cb3c60da68a..65ec1356457e9bdb1e43edac88407d8e139d0f95 100644 (file)
@@ -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 %}
 <h3><a href="{% url telemeta-geo-continents %}">{% trans "World" %}</a> /
-  {{ continent.location.name }}</h3>
-<ul>
-{% for country in continent.countries %}
-  <li><a href="{% url telemeta-geo-country-collections continent.location.flatname,country.location.flatname %}">
-    {{ country.location.name }} ({{ country.count }})</a></li>
+  {{ continent }}</h3>
+<table class="listing">
+<tr>
+    <th>{% trans "Country" %}</th>
+    <th>{% trans "Number of collections" %}</th>
+    <th>{% trans "Number of items" %}</th>
+</tr>
+{% for country in countries %}
+<tr>
+  <td>{{ country }}</td>
+  <td>
+  {% with country.collections.count as num %}
+  <a href="{% url telemeta-geo-country-collections continent.flatname,country.flatname %}">
+  {% blocktrans count num as counter %}1 collection{% plural %}{{ counter }} collections{% endblocktrans %}
+  </a>
+  {% endwith %}
+  </td>
+  <td>
+  {% with country.items.count as num %}
+  <a href="{% url telemeta-geo-country-items continent.flatname,country.flatname %}">
+  {% blocktrans count num as counter %}1 item{% plural %}{{ counter }} items {% endblocktrans %}
+  </a>
+  {% endwith %}
+  </td>
+</tr>  
 {% endfor %}
-</ul>
+</table>
 {% endblock %}
index 48c6a31a0406619429c31af6d89fef06642ae5b1..c18cd575f34e62e4ce6cb4df64a051d4dec10ff5 100644 (file)
@@ -387,9 +387,12 @@ class WebView(Component):
 
     def list_countries(self, request, continent):                    
         continent = Location.objects.by_flatname(continent)[0]
-        data = MediaCollection.objects.stat_continents(only_continent=continent)
+        countries = MediaItem.objects.by_location(continent).countries()
 
-        return render_to_response('telemeta/geo_countries.html', {'continent': data[0] })
+        return render_to_response('telemeta/geo_countries.html', {
+            'continent': continent,
+            'countries': countries
+        })
 
     def list_country_collections(self, request, continent, country):
         continent = Location.objects.by_flatname(continent)[0]