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 %} + +Records {{ first_on_page }} to {{ last_on_page }} on {{ hits }} +
Collections {{ first_on_page }} to {{ last_on_page }} on {{ hits }} {% if has_previous %} << {% endif %} {% if has_next %} >> {% endif %} diff --git a/telemeta/templates/telemeta_default/inc/mediaitem_list.html b/telemeta/templates/telemeta_default/inc/mediaitem_list.html index ed9ba755..493a6f54 100644 --- a/telemeta/templates/telemeta_default/inc/mediaitem_list.html +++ b/telemeta/templates/telemeta_default/inc/mediaitem_list.html @@ -1,7 +1,7 @@ {% load telemeta_utils %} {% if items %} {% if hits %} -
Records {{ first_on_page }} to {{ last_on_page }} on {{ hits }} +
Items {{ first_on_page }} to {{ last_on_page }} on {{ hits }}
{% if has_previous %} << {% endif %}
{% if has_next %} >> {% endif %}
diff --git a/telemeta/templatetags/telemeta_utils.py b/telemeta/templatetags/telemeta_utils.py
index 61b61cec..6223703e 100644
--- a/telemeta/templatetags/telemeta_utils.py
+++ b/telemeta/templatetags/telemeta_utils.py
@@ -6,6 +6,8 @@ import telemeta.models.dublincore as dc
from django.utils import html
from django import template
from django.utils.text import capfirst
+from telemeta import models
+from django.utils.translation import ungettext
register = template.Library()
@@ -172,3 +174,18 @@ def field_label(model, field):
@register.filter
def is_none(value):
return value is None
+
+@register.filter
+def resources_num(value):
+ model = value.model
+ count = value.count()
+ label = str(count)
+ if model == models.MediaItem:
+ label = ungettext('%(count)d item', '%(count)d items', count) % {
+ 'count': count, }
+ elif model == models.MediaCollection:
+ label = ungettext('%(count)d collection', '%(count)d collections', count) % {
+ 'count': count, }
+
+ return label
+
diff --git a/telemeta/urls.py b/telemeta/urls.py
index 711ae65c..51668b0e 100644
--- a/telemeta/urls.py
+++ b/telemeta/urls.py
@@ -138,10 +138,15 @@ urlpatterns = patterns('',
url(r'^geo/$', web_view.list_continents, name="telemeta-geo-continents"),
url(r'^geo/(?P