that.map = null;
that.init = function(list, cfg) {
+ that.cfg = cfg;
$(document).ready(function() {
that.log("init");
that.list = $(list);
return info.wrap('<div/>').parent().html();
}
+ that.showResourceInfo = function(marker, resourceElement) {
+ var info = $('<div/>').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)
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);
}
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"
--- /dev/null
+{% extends "telemeta_default/country_info.html" %}
+
--- /dev/null
+{% extends "telemeta_default/geo_country_items.html" %}
--- /dev/null
+{% load telemeta_utils %}
+{% load i18n %}
+
+<h2>{{ country }}</h2>
+<a href="{% url telemeta-geo-country-items continent.flatname,country.flatname %}">
+{{ country.items|resources_num }}
+</a>
+{% trans "in" %}
+<a href="{% url telemeta-geo-country-collections continent.flatname,country.flatname %}">
+{{ country.collections|resources_num }}
+</a>
<script src="http://www.google.com/jsapi?key={{ gmap_key }}" type="text/javascript"></script>
<script src="{% url telemeta-js "resourcemap.js" %}" type="text/javascript"></script>
<script type="text/javascript">
-var resourceMap = new ResourceMap('.continents');
+var resourceMap = new ResourceMap('.continents', {
+ 'countryInfoUri': '{% url telemeta-country-info "RESOURCEID" %}'
+});
</script>
{% endif %}
{% endblock %}
<h3>Geographic Navigator</h3>
{% if continents %}
<ul class="continents">
-{% for continent in continents %}
- <li class="name"><b><a href="{% url telemeta-geo-countries continent.location.flatname %}">{{ continent.location }}</a></b>
+{% for group in continents %}
+ <li class="name"><b><a href="{% url telemeta-geo-countries group.continent.flatname %}">{{ group.continent }}</a></b>
<ul>
- {% for country in continent.countries %}
- <li class="country_name resourcemap-element">
- <a href="{% url telemeta-geo-country-collections continent.location.flatname,country.location.flatname %}"
- title="{{ country.count }} {% trans "collections" %}">
- <span class="resourcemap-name">{{ country.location }}</span></a>
- {% if not country.location.latitude|is_none and not country.location.longitude|is_none %}
- <input type="hidden" class="resourcemap-lat" value="{{country.location.latitude}}" />
- <input type="hidden" class="resourcemap-lng" value="{{country.location.longitude}}" />
+ {% for country in group.countries %}
+ <li id="resource-{{country.id}}" class="country_name resourcemap-element">
+ <a href="{% url telemeta-geo-country-collections group.continent.flatname,country.flatname %}">
+ <span class="resourcemap-name">{{ country }}</span></a>
+ {% if not country.latitude|is_none and not country.longitude|is_none %}
+ <input type="hidden" class="resourcemap-lat" value="{{country.latitude}}" />
+ <input type="hidden" class="resourcemap-lng" value="{{country.longitude}}" />
{% endif %}
</li>
{% endfor %}
- {% if continent.countries.10 %}
- <li><a href="{% url telemeta-geo-countries continent.location.flatname %}">More..</a></li>
+ {% if group.countries.10 %}
+ <li><a href="{% url telemeta-geo-countries group.continent.flatname %}">More..</a></li>
{% endif %}
</ul>
</li>
--- /dev/null
+{% extends "telemeta/base.html" %}
+{% load telemeta_utils %}
+{% load i18n %}
+
+{% block content %}
+<h3><a href="{% url telemeta-geo-continents %}">{% trans "World" %}</a> /
+ <a href="{% url telemeta-geo-countries continent.flatname %}">{{ continent }}</a>
+ / {{ country }}</h3>
+
+{% with object_list as items %}
+{% include "telemeta/inc/mediaitem_list.html" %}
+{% endwith %}
+
+{% endblock %}
{% load telemeta_utils %}
{% if collections %}
{% if hits %}
- <p class="pagination">Records {{ first_on_page }} to {{ last_on_page }} on {{ hits }}
+ <p class="pagination">Collections {{ first_on_page }} to {{ last_on_page }} on {{ hits }}
{% if has_previous %} <a href="?page={{ previous }}&{{criteria|build_query_string}}"><<</a> {% endif %}
{% if has_next %} <a href="?page={{ next }}&{{criteria|build_query_string}}">>></a> {% endif %}
{% load telemeta_utils %}
{% if items %}
{% if hits %}
- <p class="pagination">Records {{ first_on_page }} to {{ last_on_page }} on {{ hits }}
+ <p class="pagination">Items {{ first_on_page }} to {{ last_on_page }} on {{ hits }}
{% if has_previous %} <a href="?page={{ previous }}&{{criteria|build_query_string}}"><<</a> {% endif %}
{% if has_next %} <a href="?page={{ next }}&{{criteria|build_query_string}}">>></a> {% endif %}
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()
@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
+
url(r'^geo/$', web_view.list_continents, name="telemeta-geo-continents"),
url(r'^geo/(?P<continent>[a-z_]+)/$', web_view.list_countries,
name="telemeta-geo-countries"),
- url(r'^geo/(?P<continent>[a-z_]+)/(?P<country>[a-z_]+)/$',
+ url(r'^geo/collections/(?P<continent>[a-z_]+)/(?P<country>[a-z_]+)/$',
web_view.list_country_collections,
name="telemeta-geo-country-collections"),
+ url(r'^geo/items/(?P<continent>[a-z_]+)/(?P<country>[a-z_]+)/$',
+ web_view.list_country_items,
+ name="telemeta-geo-country-items"),
url(r'^dynjs/continents.js$', web_view.get_continents_js, name="telemeta-continents-js"),
+ url(r'^geo/country_info/(?P<id>[0-9A-Z]+)/$',
+ web_view.country_info, name="telemeta-country-info"),
# CSS+Images (FIXME: for developement only)
url(r'^css/(?P<path>.*)$', 'django.views.static.serve',
return HttpResponse(template.render(context), mimetype=mimetype)
def list_continents(self, request):
- continents = MediaCollection.objects.stat_continents()
+ continents = MediaItem.objects.all().countries(group_by_continent=True)
return render_to_response('telemeta/geo_continents.html',
{'continents': continents, 'gmap_key': settings.TELEMETA_GMAP_KEY })
+ def country_info(self, request, id):
+ country = Location.objects.get(pk=id)
+ return render_to_response('telemeta/country_info.html', {
+ 'country': country, 'continent': country.continents()[0]})
+
def get_continents_js(self, request):
countries = MediaCollection.objects.list_countries()
return render_to_response('telemeta/geo_continents.js',
template_name='telemeta/geo_country_collections.html', paginate_by=20,
extra_context={'country': country, 'continent': continent})
+ def list_country_items(self, request, continent, country):
+ continent = Location.objects.by_flatname(continent)[0]
+ country = Location.objects.by_flatname(country)[0]
+ objects = MediaItem.objects.by_location(country)
+ return list_detail.object_list(request, objects,
+ template_name='telemeta/geo_country_items.html', paginate_by=20,
+ extra_context={'country': country, 'continent': continent})
+
def handle_oai_request(self, request):
url = 'http://' + request.META['HTTP_HOST'] + request.path
datasource = TelemetaOAIDataSource()