source: products/geolocation/trunk/adapters/geolocation.py

Last change on this file was 1, checked in by myroslav, 18 years ago

Building directory structure

  • Property svn:eol-style set to native
File size: 2.3 KB
Line 
1from zope.interface import implements
2from Products.geolocation.interfaces.geolocation import IGEOLocated
3from zope.app.annotation.interfaces import IAnnotations, IAnnotatable
4from Products.CMFPlone.CatalogTool import registerIndexableAttribute
5from persistent.mapping import  PersistentMapping
6
7GEOLOCATION_KEY = "geolocation.adapters.geolocation"
8
9class 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
45default = None
46
47def 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"""
61def Longitude(obj, portal, **kw):
62    adapter = IGEOLocated(obj, None)
63    if adapter:
64        return adapter.getLongitude()
65    return default
66
67def Latitude(obj, portal, **kw):
68    adapter = IGEOLocated(obj, None)
69    if adapter:
70        return adapter.getLatitude()
71    return default
72"""
73registerIndexableAttribute('geoLocation', geoLocation)
74#registerIndexableAttribute('Longitude', Longitude)
75#registerIndexableAttribute('Latitude', Latitude)
Note: See TracBrowser for help on using the repository browser.