ordered.append({'continent': c, 'countries': grouped[c]})
countries = ordered
+ else:
+ countries.sort(self.__name_cmp)
return countries
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
{% 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 %}
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]