[gmap] make gmap-views more tolerant stable
authorAdrien Di Mascio <Adrien.DiMascio@logilab.fr>
Sun, 16 Aug 2009 20:41:06 +0200
branchstable
changeset 2868 937890e25765
parent 2866 4c804711548d
child 2869 0cb160fd3cdf
child 2870 e3a5b7c3f767
[gmap] make gmap-views more tolerant - marker_icon() implementation shouldn't be required - skip entities with latitude or longitude unknown
web/views/igeocodable.py
--- a/web/views/igeocodable.py	Sun Aug 16 20:19:54 2009 +0200
+++ b/web/views/igeocodable.py	Sun Aug 16 20:41:06 2009 +0200
@@ -22,6 +22,8 @@
     __select__ = implements(IGeocodable)
 
     def call(self):
+        # remove entities that don't define latitude and longitude
+        self.rset = self.rset.filtered_rset(lambda e: e.latitude and e.longitude)
         zoomlevel = self.req.form.pop('zoomlevel', 8)
         extraparams = self.req.form.copy()
         extraparams.pop('vid', None)
@@ -41,10 +43,15 @@
 
     def build_marker_data(self, row, extraparams):
         entity = self.entity(row, 0)
+        icon = None
+        if hasattr(entity, 'marker_icon'):
+            icon = entity.marker_icon()
+        else:
+            icon = (self.req.external_resource('GMARKER_ICON'), (20, 34), (4, 34), None)
         return {'latitude': entity.latitude, 'longitude': entity.longitude,
                 'title': entity.dc_long_title(),
                 #icon defines : (icon._url, icon.size,  icon.iconAncho', icon.shadow)
-                'icon': entity.marker_icon() or (self.req.external_resource('GMARKER_ICON'), (20, 34), (4, 34), None),
+                'icon': icon,
                 'bubbleUrl': entity.absolute_url(vid='gmap-bubble', __notemplate=1, **extraparams),
                 }
 
@@ -67,7 +74,9 @@
     need_navigation = False
 
     def call(self, gmap_key, width=400, height=400, uselabel=True, urlparams=None):
-        self.req.add_js('http://maps.google.com/maps?file=api&amp;v=2&amp;key=%s' % gmap_key,
+        # remove entities that don't define latitude and longitude
+        self.rset = self.rset.filtered_rset(lambda e: e.latitude and e.longitude)
+        self.req.add_js('http://maps.google.com/maps?sensor=false&file=api&amp;v=2&amp;key=%s' % gmap_key,
                         localfile=False)
         self.req.add_js( ('cubicweb.widgets.js', 'cubicweb.gmap.js', 'gmap.utility.labeledmarker.js') )
         rql = self.rset.printable_rql()