Changeset 5889b86


Ignore:
Timestamp:
02/08/10 17:14:23 (4 years ago)
Author:
olivier <>
Branches:
master, crem, crem2, dev, dev2, diadems, feature/breadcrumbs, feature/ts-0.5, feature/ts-0.5.4, feature/writecache, forma, generic, instru_search, lam, lam2, mapsv3, merge, nlivemulti, production, release/1.4.4, sabiod, security, server, social, storage, telecaster, test, video
Children:
792cd0d
Parents:
653e7d2
git-author:
olivier <> (02/08/10 17:14:23)
git-committer:
olivier <> (02/08/10 17:14:23)
Message:

reduce geo navigator loading time, counting related resources on demand ; display both collections and items count in gmap info boxes

Location:
telemeta
Files:
4 added
8 edited

Legend:

Unmodified
Added
Removed
  • telemeta/htdocs/js/resourcemap.js

    r7365a0d r5889b86  
    66 
    77    that.init = function(list, cfg) { 
     8        that.cfg = cfg; 
    89        $(document).ready(function() { 
    910            that.log("init"); 
     
    6768    } 
    6869 
     70    that.showResourceInfo = function(marker, resourceElement) { 
     71        var info = $('<div/>').addClass('resourcemap-info'); 
     72        marker.openInfoWindowHtml(info.get(0)); 
     73        var re  = /^resource-/; 
     74        var id  = resourceElement.attr('id').replace(re, ''); 
     75        var uri = that.cfg.countryInfoUri.replace('RESOURCEID', id); 
     76         
     77        $.get(uri, function(data) { 
     78            info.html(data); 
     79        }); 
     80    } 
     81 
    6982    that.parseResources = function() { 
    7083        $('.resourcemap-element').each(function(i, e) { 
     
    7487                var lat       = parseFloat(input.attr('value')); 
    7588                var lng       = parseFloat(e.find('.resourcemap-lng').attr('value')); 
    76                 var name      = $.trim(e.find('.resourcemap-name').text()); 
    77                 var link      = e.find('a').attr('href'); 
    78                 var linktitle = e.find('a').attr('title'); 
     89                //var name      = $.trim(e.find('.resourcemap-name').text()); 
     90                //var link      = e.find('a').attr('href'); 
     91                //var linktitle = e.find('a').attr('title'); 
    7992                var marker    = new google.maps.Marker(new GLatLng(lat, lng), {title: name}); 
    80                 var info      = that.makeInfoBox(name, link, linktitle); 
     93                //var info      = that.makeInfoBox(name, link, linktitle); 
    8194                google.maps.Event.addListener(marker, "click", function() { 
    82                     marker.openInfoWindowHtml(info); 
     95                    that.showResourceInfo(marker, e); 
     96                    //marker.openInfoWindowHtml(info); 
    8397                }); 
    8498                that.map.addOverlay(marker); 
  • telemeta/models/cremquery.py

    rbe51b23 r5889b86  
    252252        descendants = LocationRelation.objects.filter(ancestor_location=location) 
    253253        return self.filter(Q(location=location) | Q(location__in=descendants)) 
     254            
     255    @staticmethod 
     256    def __name_cmp(obj1, obj2): 
     257        return unaccent_icmp(obj1.name, obj2.name) 
     258 
     259    def countries(self, group_by_continent=False): 
     260        from telemeta.models import Location 
     261        countries = [] 
     262        for id in self.filter(location__isnull=False).values_list('location', flat=True).distinct(): 
     263            location = Location.objects.get(pk=id) 
     264            for l in location.countries(): 
     265                if not l in countries: 
     266                    countries.append(l) 
     267 
     268        if group_by_continent: 
     269            grouped = {} 
     270 
     271            for country in countries: 
     272                for continent in country.continents(): 
     273                    if not grouped.has_key(continent): 
     274                        grouped[continent] = [] 
     275 
     276                    grouped[continent].append(country) 
     277                     
     278            keys = grouped.keys() 
     279            keys.sort(self.__name_cmp) 
     280            ordered = [] 
     281            for c in keys: 
     282                grouped[c].sort(self.__name_cmp) 
     283                ordered.append({'continent': c, 'countries': grouped[c]}) 
    254284             
     285            countries = ordered 
     286             
     287        return countries                     
     288 
    255289class MediaItemManager(CoreManager): 
    256290    "Manage media items queries" 
  • telemeta/templates/telemeta_default/geo_continents.html

    r7365a0d r5889b86  
    88<script src="{% url telemeta-js "resourcemap.js" %}" type="text/javascript"></script> 
    99<script type="text/javascript"> 
    10 var resourceMap = new ResourceMap('.continents'); 
     10var resourceMap = new ResourceMap('.continents', { 
     11    'countryInfoUri': '{% url telemeta-country-info "RESOURCEID" %}' 
     12}); 
    1113</script> 
    1214{% endif %} 
     
    2325{% if continents %} 
    2426<ul class="continents"> 
    25 {% for continent in continents %} 
    26   <li class="name"><b><a href="{% url telemeta-geo-countries continent.location.flatname %}">{{ continent.location }}</a></b> 
     27{% for group in continents %} 
     28  <li class="name"><b><a href="{% url telemeta-geo-countries group.continent.flatname %}">{{ group.continent }}</a></b> 
    2729    <ul> 
    28     {% for country in continent.countries %} 
    29       <li class="country_name resourcemap-element"> 
    30         <a href="{% url telemeta-geo-country-collections continent.location.flatname,country.location.flatname %}" 
    31            title="{{ country.count }} {% trans "collections" %}"> 
    32           <span class="resourcemap-name">{{ country.location }}</span></a> 
    33         {% if not country.location.latitude|is_none and not country.location.longitude|is_none %} 
    34         <input type="hidden" class="resourcemap-lat" value="{{country.location.latitude}}" /> 
    35         <input type="hidden" class="resourcemap-lng" value="{{country.location.longitude}}" /> 
     30    {% for country in group.countries %} 
     31      <li id="resource-{{country.id}}" class="country_name resourcemap-element"> 
     32        <a href="{% url telemeta-geo-country-collections group.continent.flatname,country.flatname %}"> 
     33          <span class="resourcemap-name">{{ country }}</span></a> 
     34        {% if not country.latitude|is_none and not country.longitude|is_none %} 
     35        <input type="hidden" class="resourcemap-lat" value="{{country.latitude}}" /> 
     36        <input type="hidden" class="resourcemap-lng" value="{{country.longitude}}" /> 
    3637        {% endif %} 
    3738      </li> 
    3839    {% endfor %} 
    39     {% if continent.countries.10 %} 
    40     <li><a href="{% url telemeta-geo-countries continent.location.flatname %}">More..</a></li> 
     40    {% if group.countries.10 %} 
     41    <li><a href="{% url telemeta-geo-countries group.continent.flatname %}">More..</a></li> 
    4142    {% endif %} 
    4243    </ul> 
  • telemeta/templates/telemeta_default/inc/collection_list.html

    ra2e58a9 r5889b86  
    22{% if collections %} 
    33    {% if hits %} 
    4     <p class="pagination">Records {{ first_on_page }} to {{ last_on_page }} on {{ hits }}  
     4    <p class="pagination">Collections {{ first_on_page }} to {{ last_on_page }} on {{ hits }}  
    55    &nbsp;&nbsp; 
    66    {% if has_previous %} <a href="?page={{ previous }}&amp;{{criteria|build_query_string}}">&lt;&lt;</a> {% endif %} 
  • telemeta/templates/telemeta_default/inc/mediaitem_list.html

    ra2e58a9 r5889b86  
    22{% if items %} 
    33    {% if hits %} 
    4     <p class="pagination">Records {{ first_on_page }} to {{ last_on_page }} on {{ hits }}  
     4    <p class="pagination">Items {{ first_on_page }} to {{ last_on_page }} on {{ hits }}  
    55    &nbsp;&nbsp; 
    66    {% if has_previous %} <a href="?page={{ previous }}&amp;{{criteria|build_query_string}}">&lt;&lt;</a> {% endif %} 
  • telemeta/templatetags/telemeta_utils.py

    r7365a0d r5889b86  
    77from django import template 
    88from django.utils.text import capfirst 
     9from telemeta import models 
     10from django.utils.translation import ungettext 
    911 
    1012register = template.Library() 
     
    173175def is_none(value): 
    174176    return value is None 
     177 
     178@register.filter 
     179def resources_num(value): 
     180    model = value.model 
     181    count = value.count() 
     182    label = str(count) 
     183    if model == models.MediaItem: 
     184        label = ungettext('%(count)d item', '%(count)d items', count) % { 
     185            'count': count, } 
     186    elif model == models.MediaCollection: 
     187        label = ungettext('%(count)d collection', '%(count)d collections', count) % { 
     188            'count': count, } 
     189 
     190    return label 
     191     
  • telemeta/urls.py

    rfc6b123 r5889b86  
    139139    url(r'^geo/(?P<continent>[a-z_]+)/$', web_view.list_countries,  
    140140        name="telemeta-geo-countries"), 
    141     url(r'^geo/(?P<continent>[a-z_]+)/(?P<country>[a-z_]+)/$',  
     141    url(r'^geo/collections/(?P<continent>[a-z_]+)/(?P<country>[a-z_]+)/$',  
    142142        web_view.list_country_collections,  
    143143        name="telemeta-geo-country-collections"), 
     144    url(r'^geo/items/(?P<continent>[a-z_]+)/(?P<country>[a-z_]+)/$',  
     145        web_view.list_country_items,  
     146        name="telemeta-geo-country-items"), 
    144147    url(r'^dynjs/continents.js$', web_view.get_continents_js, name="telemeta-continents-js"), 
     148    url(r'^geo/country_info/(?P<id>[0-9A-Z]+)/$',  
     149        web_view.country_info, name="telemeta-country-info"), 
    145150 
    146151    # CSS+Images (FIXME: for developement only) 
  • telemeta/web/base.py

    r7365a0d r5889b86  
    338338 
    339339    def list_continents(self, request): 
    340         continents = MediaCollection.objects.stat_continents() 
     340        continents = MediaItem.objects.all().countries(group_by_continent=True) 
    341341        return render_to_response('telemeta/geo_continents.html',  
    342342                    {'continents': continents, 'gmap_key': settings.TELEMETA_GMAP_KEY }) 
     343 
     344    def country_info(self, request, id): 
     345        country = Location.objects.get(pk=id) 
     346        return render_to_response('telemeta/country_info.html', { 
     347            'country': country, 'continent': country.continents()[0]}) 
    343348 
    344349    def get_continents_js(self, request): 
     
    359364        return list_detail.object_list(request, objects,  
    360365            template_name='telemeta/geo_country_collections.html', paginate_by=20, 
     366            extra_context={'country': country, 'continent': continent}) 
     367 
     368    def list_country_items(self, request, continent, country): 
     369        continent = Location.objects.by_flatname(continent)[0] 
     370        country = Location.objects.by_flatname(country)[0] 
     371        objects = MediaItem.objects.by_location(country) 
     372        return list_detail.object_list(request, objects,  
     373            template_name='telemeta/geo_country_items.html', paginate_by=20, 
    361374            extra_context={'country': country, 'continent': continent}) 
    362375 
Note: See TracChangeset for help on using the changeset viewer.