Did I find the right examples for you? yes no Crawl my project Python Jobs
All Samples(14) | Call(13) | Derive(0) | Import(1)
Handler to automatically do geocoding lookups for IGeoreferenceable objects that have an IGeocodableLocation adapter.
def geocodeAddressHandler(obj, event): """Handler to automatically do geocoding lookups for IGeoreferenceable objects that have an IGeocodableLocation adapter. """ # When creating the obj, it has no request - we need to get it # from the site. request = getSite().REQUEST # When we run the gecode address handler it will fire an object modified # event - but we are subscribing to this event. This will result in a # recursion unless we prevent it. if IGeoCoding.providedBy(request): return alsoProvides(request, IGeoCoding) location_adapter = queryAdapter(obj, IGeocodableLocation) if not location_adapter: return location = location_adapter.getLocationString() if location: ann = queryAdapter(obj, IAnnotations) previous_location = ann.get(LOCATION_KEY) # Only do the geocoding lookup if the location changed if not location == previous_location: geocoding_result = geocode_location(location) if geocoding_result: _place, coords, msg = geocoding_result if msg: display_status_message(msg) geo_manager = queryAdapter(obj, IGeoManager) geo_manager.setCoordinates('Point', (coords[1], coords[0])) # Update the stored location ann[LOCATION_KEY] = location noLongerProvides(request, IGeoCoding)
from collective.geo.contentlocations.interfaces import IGeoManager from collective.geo.geographer.interfaces import IGeoreferenceable from collective.geo.geographer.interfaces import IGeoreferenced from collective.geo.settings.interfaces import IGeoSettings from ftw.geo.handlers import geocodeAddressHandler
event = self.mocker.mock() geocodeAddressHandler(self.context, event) def test_geocoding_handler_with_same_location(self):
# Call the handler twice with the same context, shouldn't cause a # lookup since location didn't change. geocodeAddressHandler(self.context, event) geocodeAddressHandler(self.context, event)
self.replay() geocodeAddressHandler(self.context, event) def test_geocoding_handler_with_invalid_location(self):