Changeset 573 for tags/telemeta-0.5.0
- Timestamp:
- 02/16/10 22:24:31 (7 months ago)
- Location:
- tags/telemeta-0.5.0
- Files:
-
- 4 modified
-
. (modified) (1 prop)
-
telemeta/models/query.py (modified) (2 diffs)
-
telemeta/templates/telemeta_default/geo_countries.html (modified) (1 diff)
-
telemeta/web/base.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
tags/telemeta-0.5.0
-
tags/telemeta-0.5.0/telemeta/models/query.py
r564 r573 123 123 124 124 countries = ordered 125 else: 126 countries.sort(self.__name_cmp) 125 127 126 128 return countries … … 327 329 return unaccent_icmp(obj1.name, obj2.name) 328 330 329 def stat_continents(self, only_continent=None):330 "Return the number of collections by continents and countries as a tree"331 332 from telemeta.models.media import MediaItem333 from telemeta.models.location import Location334 335 countries = []336 for lid in MediaItem.objects.filter(location__isnull=False).values_list('location', flat=True).distinct():337 location = Location.objects.get(pk=lid)338 if not only_continent or (only_continent in location.continents()):339 for l in location.countries():340 if not l in countries:341 countries.append(l)342 343 stat = {}344 345 for country in countries:346 count = country.collections().count()347 for continent in country.continents():348 if not stat.has_key(continent):349 stat[continent] = {}350 351 stat[continent][country] = count352 353 keys1 = stat.keys()354 keys1.sort(self.__name_cmp)355 ordered = []356 for c in keys1:357 keys2 = stat[c].keys()358 keys2.sort(self.__name_cmp)359 sub = [{'location': d, 'count': stat[c][d]} for d in keys2]360 ordered.append({'location': c, 'countries': sub})361 362 return ordered363 364 331 class LocationQuerySet(CoreQuerySet): 365 332 __flatname_map = None -
tags/telemeta-0.5.0/telemeta/templates/telemeta_default/geo_countries.html
r571 r573 3 3 {% load i18n %} 4 4 5 {% block head_title %}{{ continent .location.name}} - {% trans "Geographic Navigator" %} - {{ block.super }}{% endblock %}5 {% block head_title %}{{ continent }} - {% trans "Geographic Navigator" %} - {{ block.super }}{% endblock %} 6 6 7 7 {% block content %} 8 8 <h3><a href="{% url telemeta-geo-continents %}">{% trans "World" %}</a> / 9 {{ continent.location.name }}</h3> 10 <ul> 11 {% for country in continent.countries %} 12 <li><a href="{% url telemeta-geo-country-collections continent.location.flatname,country.location.flatname %}"> 13 {{ country.location.name }} ({{ country.count }})</a></li> 9 {{ continent }}</h3> 10 <table class="listing"> 11 <tr> 12 <th>{% trans "Country" %}</th> 13 <th>{% trans "Number of collections" %}</th> 14 <th>{% trans "Number of items" %}</th> 15 </tr> 16 {% for country in countries %} 17 <tr> 18 <td>{{ country }}</td> 19 <td> 20 {% with country.collections.count as num %} 21 <a href="{% url telemeta-geo-country-collections continent.flatname,country.flatname %}"> 22 {% blocktrans count num as counter %}1 collection{% plural %}{{ counter }} collections{% endblocktrans %} 23 </a> 24 {% endwith %} 25 </td> 26 <td> 27 {% with country.items.count as num %} 28 <a href="{% url telemeta-geo-country-items continent.flatname,country.flatname %}"> 29 {% blocktrans count num as counter %}1 item{% plural %}{{ counter }} items {% endblocktrans %} 30 </a> 31 {% endwith %} 32 </td> 33 </tr> 14 34 {% endfor %} 15 </ ul>35 </table> 16 36 {% endblock %} -
tags/telemeta-0.5.0/telemeta/web/base.py
r561 r573 388 388 def list_countries(self, request, continent): 389 389 continent = Location.objects.by_flatname(continent)[0] 390 data = MediaCollection.objects.stat_continents(only_continent=continent) 391 392 return render_to_response('telemeta/geo_countries.html', {'continent': data[0] }) 390 countries = MediaItem.objects.by_location(continent).countries() 391 392 return render_to_response('telemeta/geo_countries.html', { 393 'continent': continent, 394 'countries': countries 395 }) 393 396 394 397 def list_country_collections(self, request, continent, country):
