web/views/igeocodable.py
branchtls-sprint
changeset 692 800592b8d39b
parent 553 c69eac8298c0
child 728 a95b284150d1
equal deleted inserted replaced
691:35133d86970b 692:800592b8d39b
     1 # -*- coding: utf-8 -*-
     1 """Specific views for entities implementing IGeocodable
       
     2 
       
     3 :organization: Logilab
       
     4 :copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
       
     5 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
       
     6 """
       
     7 __docformat__ = "restructuredtext en"
     2 
     8 
     3 import simplejson
     9 import simplejson
     4 
    10 
     5 from cubicweb.interfaces import IGeocodable
    11 from cubicweb.interfaces import IGeocodable
     6 from cubicweb.common.view import EntityView
    12 from cubicweb.common.view import EntityView
     7 from cubicweb.common.selectors import implement_interface
    13 from cubicweb.selectors import implements
     8 
    14 
     9 class GeocodingJsonView(EntityView):
    15 class GeocodingJsonView(EntityView):
    10     id = 'geocoding-json'
    16     id = 'geocoding-json'
    11     binary = True
    17     binary = True
    12     templatable = False
    18     templatable = False
    13     content_type = 'application/json'
    19     content_type = 'application/json'
    14 
    20 
    15     __selectors__ = (implement_interface,)
    21     __selectors__ = implements(IGeocodable)
    16     accepts_interfaces = (IGeocodable,)
       
    17 
    22 
    18     def call(self):
    23     def call(self):
    19         zoomlevel = self.req.form.pop('zoomlevel', 8)
    24         zoomlevel = self.req.form.pop('zoomlevel', 8)
    20         extraparams = self.req.form.copy()
    25         extraparams = self.req.form.copy()
    21         extraparams.pop('vid', None)
    26         extraparams.pop('vid', None)
    44 
    49 
    45 
    50 
    46 class GoogleMapBubbleView(EntityView):
    51 class GoogleMapBubbleView(EntityView):
    47     id = 'gmap-bubble'
    52     id = 'gmap-bubble'
    48 
    53 
    49     __selectors__ = (implement_interface,)
    54     __selectors__ = implements(IGeocodable)
    50     accepts_interfaces = (IGeocodable,)
       
    51 
    55 
    52     def cell_call(self, row, col):
    56     def cell_call(self, row, col):
    53         entity = self.entity(row, col)
    57         entity = self.entity(row, col)
    54         self.w(u'<div>%s</div>' % entity.view('oneline'))
    58         self.w(u'<div>%s</div>' % entity.view('oneline'))
    55         # FIXME: we should call something like address-view if available
    59         # FIXME: we should call something like address-view if available
    56 
    60 
    57 
    61 
    58 class GoogleMapsView(EntityView):
    62 class GoogleMapsView(EntityView):
    59     id = 'gmap-view'
    63     id = 'gmap-view'
    60 
    64 
    61     __selectors__ = (implement_interface,)
    65     __selectors__ = implements(IGeocodable)
    62     accepts_interfaces = (IGeocodable,)
       
    63     need_navigation = False
    66     need_navigation = False
    64 
    67 
    65     def call(self, gmap_key, width=400, height=400, uselabel=True, urlparams=None):
    68     def call(self, gmap_key, width=400, height=400, uselabel=True, urlparams=None):
    66         self.req.add_js('http://maps.google.com/maps?file=api&amp;v=2&amp;key=%s' % gmap_key,
    69         self.req.add_js('http://maps.google.com/maps?file=api&amp;v=2&amp;key=%s' % gmap_key,
    67                         localfile=False);
    70                         localfile=False);