web/views/igeocodable.py
changeset 3377 dd9d292b6a6d
parent 3163 edfe43ceaa35
child 3451 6b46d73823f5
equal deleted inserted replaced
3376:f5c69485381f 3377:dd9d292b6a6d
    12 from cubicweb.interfaces import IGeocodable
    12 from cubicweb.interfaces import IGeocodable
    13 from cubicweb.view import EntityView
    13 from cubicweb.view import EntityView
    14 from cubicweb.selectors import implements
    14 from cubicweb.selectors import implements
    15 
    15 
    16 class GeocodingJsonView(EntityView):
    16 class GeocodingJsonView(EntityView):
    17     id = 'geocoding-json'
    17     __regid__ = 'geocoding-json'
       
    18     __select__ = implements(IGeocodable)
       
    19 
    18     binary = True
    20     binary = True
    19     templatable = False
    21     templatable = False
    20     content_type = 'application/json'
    22     content_type = 'application/json'
    21 
       
    22     __select__ = implements(IGeocodable)
       
    23 
    23 
    24     def call(self):
    24     def call(self):
    25         # remove entities that don't define latitude and longitude
    25         # remove entities that don't define latitude and longitude
    26         self.rset = self.rset.filtered_rset(lambda e: e.latitude and e.longitude)
    26         self.rset = self.rset.filtered_rset(lambda e: e.latitude and e.longitude)
    27         zoomlevel = self.req.form.pop('zoomlevel', 8)
    27         zoomlevel = self.req.form.pop('zoomlevel', 8)
    55                 'bubbleUrl': entity.absolute_url(vid='gmap-bubble', __notemplate=1, **extraparams),
    55                 'bubbleUrl': entity.absolute_url(vid='gmap-bubble', __notemplate=1, **extraparams),
    56                 }
    56                 }
    57 
    57 
    58 
    58 
    59 class GoogleMapBubbleView(EntityView):
    59 class GoogleMapBubbleView(EntityView):
    60     id = 'gmap-bubble'
    60     __regid__ = 'gmap-bubble'
    61 
       
    62     __select__ = implements(IGeocodable)
    61     __select__ = implements(IGeocodable)
    63 
    62 
    64     def cell_call(self, row, col):
    63     def cell_call(self, row, col):
    65         entity = self.rset.get_entity(row, col)
    64         entity = self.rset.get_entity(row, col)
    66         self.w(u'<div>%s</div>' % entity.view('oneline'))
    65         self.w(u'<div>%s</div>' % entity.view('oneline'))
    67         # FIXME: we should call something like address-view if available
    66         # FIXME: we should call something like address-view if available
    68 
    67 
    69 
    68 
    70 class GoogleMapsView(EntityView):
    69 class GoogleMapsView(EntityView):
    71     id = 'gmap-view'
    70     __regid__ = 'gmap-view'
       
    71     __select__ = implements(IGeocodable)
    72 
    72 
    73     __select__ = implements(IGeocodable)
       
    74     need_navigation = False
    73     need_navigation = False
    75 
    74 
    76     def call(self, gmap_key, width=400, height=400, uselabel=True, urlparams=None):
    75     def call(self, gmap_key, width=400, height=400, uselabel=True, urlparams=None):
    77         self.req.demote_to_html()
    76         self.req.demote_to_html()
    78         # remove entities that don't define latitude and longitude
    77         # remove entities that don't define latitude and longitude
    89                u'cubicweb:wdgtype="GMapWidget" cubicweb:loadtype="auto" '
    88                u'cubicweb:wdgtype="GMapWidget" cubicweb:loadtype="auto" '
    90                u'cubicweb:loadurl="%s" cubicweb:uselabel="%s"> </div>' % (width, height, loadurl, uselabel))
    89                u'cubicweb:loadurl="%s" cubicweb:uselabel="%s"> </div>' % (width, height, loadurl, uselabel))
    91 
    90 
    92 
    91 
    93 class GoogeMapsLegend(EntityView):
    92 class GoogeMapsLegend(EntityView):
    94     id = 'gmap-legend'
    93     __regid__ = 'gmap-legend'
    95 
    94 
    96     def call(self):
    95     def call(self):
    97         self.w(u'<ol>')
    96         self.w(u'<ol>')
    98         for rowidx in xrange(len(self.rset)):
    97         for rowidx in xrange(len(self.rset)):
    99             self.w(u'<li>')
    98             self.w(u'<li>')