diff -r bb14dc9848ec -r 7fd6c52ef878 web/views/igeocodable.py --- a/web/views/igeocodable.py Mon Feb 11 11:47:50 2013 +0100 +++ b/web/views/igeocodable.py Mon Dec 17 14:03:56 2012 +0100 @@ -17,121 +17,21 @@ # with CubicWeb. If not, see . """Specific views for entities implementing IGeocodable""" -__docformat__ = "restructuredtext en" - -from cubicweb.interfaces import IGeocodable -from cubicweb.view import EntityView, EntityAdapter, implements_adapter_compat -from cubicweb.predicates import implements, adaptable -from cubicweb.utils import json_dumps - -class IGeocodableAdapter(EntityAdapter): - """interface required by geocoding views such as gmap-view""" - __needs_bw_compat__ = True - __regid__ = 'IGeocodable' - __select__ = implements(IGeocodable, warn=False) # XXX for bw compat, should be abstract - - @property - @implements_adapter_compat('IGeocodable') - def latitude(self): - """returns the latitude of the entity in degree (-90 < float < +90)""" - raise NotImplementedError +try: + from cubes.geocoding.views import (IGeocodableAdapter, + GeocodingJsonView, + GoogleMapBubbleView, + GoogleMapsView, + GoogeMapsLegend) - @property - @implements_adapter_compat('IGeocodable') - def longitude(self): - """returns the longitude of the entity in degree (-180 < float < +180)""" - raise NotImplementedError - - @implements_adapter_compat('IGeocodable') - def marker_icon(self): - """returns the icon that should be used as the marker. - - an icon is defined by a 4-uple: - - (icon._url, icon.size, icon.iconAnchor, icon.shadow) - """ - return (self._cw.uiprops['GMARKER_ICON'], (20, 34), (4, 34), None) - - -class GeocodingJsonView(EntityView): - __regid__ = 'geocoding-json' - __select__ = adaptable('IGeocodable') - - binary = True - templatable = False - content_type = 'application/json' + from logilab.common.deprecation import class_moved - def call(self): - zoomlevel = self._cw.form.pop('zoomlevel', None) - extraparams = self._cw.form.copy() - extraparams.pop('vid', None) - extraparams.pop('rql', None) - markers = [] - for entity in self.cw_rset.entities(): - igeocodable = entity.cw_adapt_to('IGeocodable') - # remove entities that don't define latitude and longitude - if not (igeocodable.latitude and igeocodable.longitude): - continue - markers.append(self.build_marker_data(entity, igeocodable, - extraparams)) - if not markers: - return - geodata = { - 'markers': markers, - } - if zoomlevel: - geodata['zoomlevel'] = int(zoomlevel) - self.w(json_dumps(geodata)) - - def build_marker_data(self, entity, igeocodable, extraparams): - return {'latitude': igeocodable.latitude, - 'longitude': igeocodable.longitude, - 'icon': igeocodable.marker_icon(), - 'title': entity.dc_long_title(), - 'bubbleUrl': entity.absolute_url( - vid='gmap-bubble', __notemplate=1, **extraparams), - } - - -class GoogleMapBubbleView(EntityView): - __regid__ = 'gmap-bubble' - __select__ = adaptable('IGeocodable') - - def cell_call(self, row, col): - entity = self.cw_rset.get_entity(row, col) - self.w(u'
%s
' % entity.view('oneline')) - # FIXME: we should call something like address-view if available - - -class GoogleMapsView(EntityView): - __regid__ = 'gmap-view' - __select__ = adaptable('IGeocodable') - - paginable = False - - def call(self, gmap_key, width=400, height=400, uselabel=True, urlparams=None): - self._cw.demote_to_html() - self._cw.add_js('http://maps.google.com/maps?sensor=false&file=api&v=2&key=%s' - % gmap_key, localfile=False) - self._cw.add_js( ('cubicweb.widgets.js', 'cubicweb.gmap.js', 'gmap.utility.labeledmarker.js') ) - rql = self.cw_rset.printable_rql() - if urlparams is None: - loadurl = self._cw.build_url(rql=rql, vid='geocoding-json') - else: - loadurl = self._cw.build_url(rql=rql, vid='geocoding-json', **urlparams) - self.w(u'
' - % (width, height, loadurl, uselabel)) - - -class GoogeMapsLegend(EntityView): - __regid__ = 'gmap-legend' - - def call(self): - self.w(u'
    ') - for rowidx in xrange(len(self.cw_rset)): - self.w(u'
  1. ') - self.wview('listitem', self.cw_rset, row=rowidx, col=0) - self.w(u'
  2. ') - self.w(u'
') + msg = '[3.17] cubicweb.web.views.igeocodable moved to cubes.geocoding.views' + IGeocodableAdapter = class_moved(IGeocodableAdapter, message=msg) + GeocodingJsonView = class_moved(GeocodingJsonView, message=msg) + GoogleMapBubbleView = class_moved(GoogleMapBubbleView, message=msg) + GoogleMapsView = class_moved(GoogleMapsView, message=msg) + GoogeMapsLegend = class_moved(GoogeMapsLegend, message=msg) +except ImportError: + from cubicweb.web import LOGGER + LOGGER.warning('[3.17] igeocoding extracted to cube geocoding that was not found. try installing it.')