From: olivier <> Date: Mon, 8 Feb 2010 16:14:23 +0000 (+0000) Subject: reduce geo navigator loading time, counting related resources on demand ; display... X-Git-Tag: 1.1~561 X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=5889b86535d21eb01ede0ef5e42405505fcdc32b;p=telemeta.git reduce geo navigator loading time, counting related resources on demand ; display both collections and items count in gmap info boxes --- diff --git a/telemeta/htdocs/js/resourcemap.js b/telemeta/htdocs/js/resourcemap.js index f3cd29cd..0fcd16a5 100644 --- a/telemeta/htdocs/js/resourcemap.js +++ b/telemeta/htdocs/js/resourcemap.js @@ -5,6 +5,7 @@ function ResourceMap(list, cfg) { that.map = null; that.init = function(list, cfg) { + that.cfg = cfg; $(document).ready(function() { that.log("init"); that.list = $(list); @@ -66,6 +67,18 @@ function ResourceMap(list, cfg) { return info.wrap('
').parent().html(); } + that.showResourceInfo = function(marker, resourceElement) { + var info = $('
').addClass('resourcemap-info'); + marker.openInfoWindowHtml(info.get(0)); + var re = /^resource-/; + var id = resourceElement.attr('id').replace(re, ''); + var uri = that.cfg.countryInfoUri.replace('RESOURCEID', id); + + $.get(uri, function(data) { + info.html(data); + }); + } + that.parseResources = function() { $('.resourcemap-element').each(function(i, e) { e = $(e) @@ -73,13 +86,14 @@ function ResourceMap(list, cfg) { if (input.length) { var lat = parseFloat(input.attr('value')); var lng = parseFloat(e.find('.resourcemap-lng').attr('value')); - var name = $.trim(e.find('.resourcemap-name').text()); - var link = e.find('a').attr('href'); - var linktitle = e.find('a').attr('title'); + //var name = $.trim(e.find('.resourcemap-name').text()); + //var link = e.find('a').attr('href'); + //var linktitle = e.find('a').attr('title'); var marker = new google.maps.Marker(new GLatLng(lat, lng), {title: name}); - var info = that.makeInfoBox(name, link, linktitle); + //var info = that.makeInfoBox(name, link, linktitle); google.maps.Event.addListener(marker, "click", function() { - marker.openInfoWindowHtml(info); + that.showResourceInfo(marker, e); + //marker.openInfoWindowHtml(info); }); that.map.addOverlay(marker); } diff --git a/telemeta/models/cremquery.py b/telemeta/models/cremquery.py index fd4d42e3..bb13949e 100644 --- a/telemeta/models/cremquery.py +++ b/telemeta/models/cremquery.py @@ -251,7 +251,41 @@ class MediaItemQuerySet(CoreQuerySet): from telemeta.models import LocationRelation descendants = LocationRelation.objects.filter(ancestor_location=location) return self.filter(Q(location=location) | Q(location__in=descendants)) + + @staticmethod + def __name_cmp(obj1, obj2): + return unaccent_icmp(obj1.name, obj2.name) + + def countries(self, group_by_continent=False): + from telemeta.models import Location + countries = [] + for id in self.filter(location__isnull=False).values_list('location', flat=True).distinct(): + location = Location.objects.get(pk=id) + for l in location.countries(): + if not l in countries: + countries.append(l) + + if group_by_continent: + grouped = {} + + for country in countries: + for continent in country.continents(): + if not grouped.has_key(continent): + grouped[continent] = [] + + grouped[continent].append(country) + + keys = grouped.keys() + keys.sort(self.__name_cmp) + ordered = [] + for c in keys: + grouped[c].sort(self.__name_cmp) + ordered.append({'continent': c, 'countries': grouped[c]}) + countries = ordered + + return countries + class MediaItemManager(CoreManager): "Manage media items queries" diff --git a/telemeta/templates/telemeta/country_info.html b/telemeta/templates/telemeta/country_info.html new file mode 100644 index 00000000..15159c6e --- /dev/null +++ b/telemeta/templates/telemeta/country_info.html @@ -0,0 +1,2 @@ +{% extends "telemeta_default/country_info.html" %} + diff --git a/telemeta/templates/telemeta/geo_country_items.html b/telemeta/templates/telemeta/geo_country_items.html new file mode 100644 index 00000000..ca2104ff --- /dev/null +++ b/telemeta/templates/telemeta/geo_country_items.html @@ -0,0 +1 @@ +{% extends "telemeta_default/geo_country_items.html" %} diff --git a/telemeta/templates/telemeta_default/country_info.html b/telemeta/templates/telemeta_default/country_info.html new file mode 100644 index 00000000..feaf87e0 --- /dev/null +++ b/telemeta/templates/telemeta_default/country_info.html @@ -0,0 +1,11 @@ +{% load telemeta_utils %} +{% load i18n %} + +

{{ country }}

+ +{{ country.items|resources_num }} + +{% trans "in" %} + +{{ country.collections|resources_num }} + diff --git a/telemeta/templates/telemeta_default/geo_continents.html b/telemeta/templates/telemeta_default/geo_continents.html index 4f60f5bf..8a6867aa 100644 --- a/telemeta/templates/telemeta_default/geo_continents.html +++ b/telemeta/templates/telemeta_default/geo_continents.html @@ -7,7 +7,9 @@ {% endif %} {% endblock %} @@ -22,22 +24,21 @@ var resourceMap = new ResourceMap('.continents');

Geographic Navigator

{% if continents %}