[1] | 1 | from zope.interface import implements |
---|
| 2 | from Products.geolocation.interfaces.geolocation import IGEOLocated |
---|
| 3 | from zope.app.annotation.interfaces import IAnnotations, IAnnotatable |
---|
| 4 | from Products.CMFPlone.CatalogTool import registerIndexableAttribute |
---|
| 5 | from persistent.mapping import PersistentMapping |
---|
| 6 | |
---|
| 7 | GEOLOCATION_KEY = "geolocation.adapters.geolocation" |
---|
| 8 | |
---|
| 9 | class GEOLocated(object): |
---|
| 10 | """ geolocation |
---|
| 11 | """ |
---|
| 12 | implements(IGEOLocated) |
---|
| 13 | |
---|
| 14 | def __init__(self, context): |
---|
| 15 | """ init """ |
---|
| 16 | self.annotations = IAnnotations(context) |
---|
| 17 | self.geolocation = self.annotations.get(GEOLOCATION_KEY, None) |
---|
| 18 | if self.geolocation == None: |
---|
| 19 | self.annotations[GEOLOCATION_KEY] = PersistentMapping() |
---|
| 20 | self.geolocation = self.annotations[GEOLOCATION_KEY] |
---|
| 21 | self.geolocation['latitude'] = None |
---|
| 22 | self.geolocation['longitude'] = None |
---|
| 23 | |
---|
| 24 | def getLongitude(self): |
---|
| 25 | """ return longtitude """ |
---|
| 26 | return self.geolocation['longitude'] |
---|
| 27 | |
---|
| 28 | def getLatitude(self): |
---|
| 29 | """ return latitude """ |
---|
| 30 | return self.geolocation['latitude'] |
---|
| 31 | |
---|
| 32 | def setLongitude(self, value): |
---|
| 33 | """ set longtitude """ |
---|
| 34 | self.geolocation['longitude'] = float(value) |
---|
| 35 | |
---|
| 36 | def setLatitude(self, value): |
---|
| 37 | """ set latitutde """ |
---|
| 38 | self.geolocation['latitude'] = float(value) |
---|
| 39 | |
---|
| 40 | def setLocation(self, latitude, longitude): |
---|
| 41 | """ set location """ |
---|
| 42 | self.geolocation['longitude'] = float(longitude) |
---|
| 43 | self.geolocation['latitude'] = float(latitude) |
---|
| 44 | |
---|
| 45 | default = None |
---|
| 46 | |
---|
| 47 | def geoLocation(obj, portal, **kw): |
---|
| 48 | """ return the location list """ |
---|
| 49 | if hasattr(obj.aq_base, 'geoLocation'): |
---|
| 50 | return obj.geoLocation() |
---|
| 51 | adapter = IGEOLocated(obj, None) |
---|
| 52 | if adapter: |
---|
| 53 | lng = adapter.getLongitude() |
---|
| 54 | lat = adapter.getLatitude() |
---|
| 55 | if not (lat or lng): |
---|
| 56 | return None |
---|
| 57 | else: |
---|
| 58 | return (lat, lng) |
---|
| 59 | return default |
---|
| 60 | """ |
---|
| 61 | def Longitude(obj, portal, **kw): |
---|
| 62 | adapter = IGEOLocated(obj, None) |
---|
| 63 | if adapter: |
---|
| 64 | return adapter.getLongitude() |
---|
| 65 | return default |
---|
| 66 | |
---|
| 67 | def Latitude(obj, portal, **kw): |
---|
| 68 | adapter = IGEOLocated(obj, None) |
---|
| 69 | if adapter: |
---|
| 70 | return adapter.getLatitude() |
---|
| 71 | return default |
---|
| 72 | """ |
---|
| 73 | registerIndexableAttribute('geoLocation', geoLocation) |
---|
| 74 | #registerIndexableAttribute('Longitude', Longitude) |
---|
| 75 | #registerIndexableAttribute('Latitude', Latitude) |
---|