Changeset 722

Show
Ignore:
Timestamp:
01/03/07 07:47:41
Author:
crchemist
Message:

Now geolocation uses geo interfaces for point objects.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • geolocation/branches/crchemist-geo_refactoring/Extensions/Install.py

    r721 r722  
    6868    out = StringIO() 
    6969    out.write('setupSkin... \n') 
    70     setupSkin(self, out, PROJECTNAME)     
     70    setupSkin(self, out, PROJECTNAME) 
    7171    catalog = getToolByName(self, 'portal_catalog') 
    7272    if 'geoLocation' not in catalog.indexes(): 
  • geolocation/branches/crchemist-geo_refactoring/adapters/geolocation.py

    r721 r722  
    11from zope.interface import implements 
    2 from Products.geolocation.interfaces.geolocation import IGEOLocated 
     2from geo.interfaces import IPoint 
    33from zope.app.annotation.interfaces import IAnnotations, IAnnotatable 
    44from Products.CMFPlone.CatalogTool import registerIndexableAttribute 
     
    66 
    77GEOLOCATION_KEY = "geolocation.adapters.geolocation" 
    8  
    9 class GEOLocated(object): 
    10     """ geolocation 
    11     """ 
    12     implements(IGEOLocated) 
     8class Point(object): 
     9    implements(IPoint) 
    1310 
    1411    def __init__(self, context): 
    1512        """ init  """ 
    1613        self.annotations = IAnnotations(context) 
    17         self.geolocation = self.annotations.get(GEOLOCATION_KEY, None) 
    18         if self.geolocation == None: 
     14        self.point = self.annotations.get(GEOLOCATION_KEY, None) 
     15        if self.point == None: 
    1916            self.annotations[GEOLOCATION_KEY] = PersistentMapping() 
    20             self.geolocation = self.annotations[GEOLOCATION_KEY] 
    21             self.geolocation['latitude']  = None 
    22             self.geolocation['longitude'] = None 
     17            self.point = self.annotations[GEOLOCATION_KEY] 
     18            self.point['targetId'] = '' 
     19            self.point['extrude'] = 0 
     20            self.point['tessellate'] = 0 
     21            self.point['altitudeMode'] = 'clampToGround' 
     22            self.point['coordinates']  = (0,0,0) 
    2323 
    24     def getLongitude(self):  
    25         """ return longtitude """ 
    26         return self.geolocation['longitude'] 
     24    def getCoordinates(self): 
     25        return self.point['coordinates'] 
    2726 
    28     def getLatitude(self): 
    29         """ return latitude """ 
    30         return self.geolocation['latitude'] 
     27    def setCoordinates(self, coordinates): 
     28        self.point['coordinates'] = coordinates 
    3129 
    32     def setLongitude(self, value): 
    33         """ set longtitude """ 
    34         self.geolocation['longitude'] = float(value) 
     30    def getAltitudeMode(self): 
     31        return self.point['altitudeMode'] 
    3532 
    36     def setLatitude(self, value): 
    37         """ set latitutde """ 
    38         self.geolocation['latitude'] = float(value) 
     33    def setAltitudeMode(self, altitudeMode): 
     34        self.point['altitudeMode'] = altitudeMode 
    3935 
    40     def setLocation(self, latitude, longitude): 
    41         """ set location """ 
    42         self.geolocation['longitude'] = float(longitude) 
    43         self.geolocation['latitude'] = float(latitude) 
     36    def getTessellate(self): 
     37        return self.point['tessellate'] 
     38 
     39    def setTessellate(self, tessellate): 
     40        self.point['tessellate'] = tessellate 
     41 
     42    def getExtrude(self): 
     43        return self.point['extrude'] 
     44 
     45    def setExtrude(self, extrude): 
     46        self.point['extrude'] = extrude 
     47 
     48    def getTargetId(self): 
     49        return self.point['targetId'] 
     50 
     51    def setTargetId(self, targetId): 
     52        self.point['targetId'] = targetId 
     53 
     54    coordinates = property(getCoordinates, setCoordinates, """ see interface """) 
     55    altitudeMode = property(getAltitudeMode, setAltitudeMode, """ see interface """) 
     56    tessellate = property(getTessellate, setTessellate, """ see interface """) 
     57    extrude = property(getExtrude, setExtrude, """ see interface """) 
     58    targetId = property(getTargetId, setTargetId, """ see interface """) 
    4459 
    4560default = None 
    46  
    4761def geoLocation(obj, portal, **kw): 
    4862    """ return the location list """ 
    4963    if hasattr(obj.aq_base, 'geoLocation'): 
    5064        return obj.geoLocation() 
    51     adapter = IGEOLocated(obj, None) 
     65    adapter = IPoint(obj, None) 
    5266    if adapter: 
    53         lng = adapter.getLongitude() 
    54         lat = adapter.getLatitude() 
    55         if not (lat or lng): 
     67        coord = adapter.coordinates[0:2] 
     68        if not coord: 
    5669            return None 
    5770        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() 
     71            return coord 
    6572    return default 
    6673 
    67 def Latitude(obj, portal, **kw): 
    68     adapter = IGEOLocated(obj, None) 
    69     if adapter: 
    70         return adapter.getLatitude() 
    71     return default 
    72 """ 
    7374registerIndexableAttribute('geoLocation', geoLocation) 
    74 #registerIndexableAttribute('Longitude', Longitude) 
    75 #registerIndexableAttribute('Latitude', Latitude) 
  • geolocation/branches/crchemist-geo_refactoring/browser/location.py

    r721 r722  
    66 
    77# Product imports 
    8 from Products.geolocation.interfaces.geolocation import IGEOLocated, IGEOLocatedView 
     8from geo.interfaces import IPoint 
     9from Products.geolocation.interfaces.geolocation import IPointView 
    910 
    10 class GEOLocatedView(BrowserView): 
     11class PointView(BrowserView): 
    1112 
    12     implements(IGEOLocatedView) 
     13    implements(IPointView) 
    1314 
    1415    def __init__(self, context, request): 
     
    1617        self.context = context 
    1718        self.request = request 
    18         self.location = IGEOLocated(self.context, None) 
    19         self.latitude = self.location and self.location.getLatitude() or None 
    20         self.longitude = self.location and self.location.getLongitude() or None 
     19        self.location = IPoint(self.context, None) 
     20        self.longitude = self.location and self.location.coordinates[0] or None 
     21        self.latitude = self.location and self.location.coordinates[1] or None 
    2122 
    2223    def editLocation(self, latitude=None, longitude=None): 
    2324        """ update location properties """ 
    24         self.location.setLocation(latitude, longitude
     25        self.location.coordinates = (longitude, latitude,0
    2526        self.context.reindexObject() 
    2627 
    2728    def getLatitude(self): 
    28        """ return location latitude """ 
     29       """ return point latitude """ 
    2930       return self.latitude 
    3031 
    3132    def getLongitude(self): 
    32        """ return location longitude """ 
     33       """ return point longitude """ 
    3334       return self.longitude 
  • geolocation/branches/crchemist-geo_refactoring/configure.zcml

    r721 r722  
    2121  <adapter 
    2222      for="Products.ATContentTypes.interface.document.IATDocument" 
    23       provides=".interfaces.geolocation.IGEOLocated
    24       factory=".adapters.geolocation.GEOLocated
     23      provides="geo.interfaces.IPoint
     24      factory=".adapters.geolocation.Point
    2525      /> 
    2626  <adapter 
    2727      for="Products.ATContentTypes.interface.event.IATEvent" 
    28       provides=".interfaces.geolocation.IGEOLocated
    29       factory=".adapters.geolocation.GEOLocated
     28      provides="geo.interfaces.IPoint
     29      factory=".adapters.geolocation.Point
    3030      /> 
    3131  <adapter 
    3232      for="Products.ATContentTypes.interface.link.IATLink" 
    33       provides=".interfaces.geolocation.IGEOLocated
    34       factory=".adapters.geolocation.GEOLocated
     33      provides="geo.interfaces.IPoint
     34      factory=".adapters.geolocation.Point
    3535      /> 
    3636  <adapter 
    3737      for="Products.ATContentTypes.interface.image.IATImage" 
    38       provides=".interfaces.geolocation.IGEOLocated
    39       factory=".adapters.geolocation.GEOLocated
     38      provides="geo.interfaces.IPoint
     39      factory=".adapters.geolocation.Point
    4040      /> 
    4141  <adapter 
    4242      for="Products.ATContentTypes.interface.news.IATNewsItem" 
    43       provides=".interfaces.geolocation.IGEOLocated
    44       factory=".adapters.geolocation.GEOLocated
     43      provides="geo.interfaces.IPoint
     44      factory=".adapters.geolocation.Point
    4545      /> 
    4646 
     
    8282      for="*" 
    8383      name="LocationView" 
    84       class=".browser.location.GEOLocatedView" 
     84      class=".browser.location.PointView" 
    8585      permission="cmf.ModifyPortalContent" 
    86       allowed_interface=".interfaces.geolocation.IGEOLocatedView" 
     86      allowed_interface=".interfaces.geolocation.IPointView" 
    8787      /> 
    8888 
  • geolocation/branches/crchemist-geo_refactoring/interfaces/geolocation.py

    r721 r722  
    33from zope.schema import Float 
    44 
    5 class IGEOLocated(Interface): 
    6     """GEO location cordinates 
    7     """ 
    8     """ 
    9     longitude = Float( 
    10         title=u"Longitude", 
    11         description=u"", 
    12         required = False ) 
    13  
    14     latitude = Float( 
    15         title=u"Latitude", 
    16         description=u"", 
    17         required = False ) 
    18     """ 
    19      
    20     def getLongitude(): 
    21         """ return longtitude """ 
    22  
    23     def getLatitude(): 
    24         """ return latitude """ 
    25      
    26     def setLongitude(value): 
    27         """ set longtitude """ 
    28      
    29     def setLatitude(value): 
    30         """ set latitutde """ 
    31  
    32     def setLocation(latitude, longitude): 
    33        """ set location  """ 
    34  
    35 class IGEOLocatedView(Interface): 
     5class IPointView(Interface): 
    366    """browser view 
    377    """ 
     
    4111 
    4212    def getLatitude(): 
    43         """ return geo latitude """ 
     13        """ return point latitude """ 
    4414 
    4515    def getLongitude(): 
    46         """ return geo longitude """ 
     16        """ return point longitude """ 
  • geolocation/branches/crchemist-geo_refactoring/tests/commonTestingStuff.py

    r721 r722  
    44from Products.CMFCore.utils import getToolByName 
    55 
    6 from Products.geolocation.interfaces.geolocation import IGEOLocated, IGEOLocatedView 
     6from geo.interfaces import IPoint 
     7from Products.geolocation.interfaces.geolocation import IPointView 
    78from Products.geolocation.interfaces.geomap import IGEOMap, IGEOMapView 
    8 from Products.geolocation.adapters.geolocation import GEOLocated 
     9from Products.geolocation.adapters.geolocation import Point 
    910from Products.geolocation.adapters.geomap import GEOMap 
    10 from Products.geolocation.browser.location import GEOLocatedView 
     11from Products.geolocation.browser.location import PointView 
    1112from Products.geolocation.browser.map import GEOMapView 
    1213 
     
    3738LATITUDE = 2.3 
    3839LONGITUDE = 3.2 
     40ALTITUDE = 2.1 
    3941MAP_CENTER = (9,9) 
    4042MAP_ZOOM = 6 
  • geolocation/branches/crchemist-geo_refactoring/tests/testAdapters.py

    r721 r722  
    1313    def testAdapterInterface(self): 
    1414        """ Test adapters' for intefaces """ 
    15         verifyClass(IGEOLocated, GEOLocated
     15        verifyClass(IPoint, Point
    1616        verifyClass(IGEOMap, GEOMap) 
    1717 
    1818    def testBrowserInterface(self): 
    1919        """ Test browsers' for intefaces """ 
    20         verifyClass(IGEOLocatedView, GEOLocatedView) 
     20        verifyClass(IPointView, PointView) 
    2121        verifyClass(IGEOMapView, GEOMapView) 
    2222 
     
    2828        self.folder.invokeFactory('Document', 'test_page') 
    2929        self.page = self.folder.test_page 
    30         self.adapter = IGEOLocated(self.page) 
    31         self.adapter.geolocation['latitude'] = LATITUDE 
    32         self.adapter.geolocation['longitude'] = LONGITUDE 
     30        self.adapter = IPoint(self.page) 
     31        self.adapter.coordinates = (LONGITUDE, LATITUDE, ALTITUDE) 
    3332 
    3433    def testImplementation(self): 
    3534        """ Test adapter implementation """ 
    36         IGEOLocated.implementedBy(GEOLocated
     35        IPoint.implementedBy(Point
    3736 
    3837    def testGetters(self): 
    3938        """ Test adapters' getters """ 
    40         self.failUnlessEqual(self.adapter.getLongitude(), LONGITUDE) 
    41         self.failUnlessEqual(self.adapter.getLatitude(), LATITUDE) 
    42  
    43     def testSetters(self): 
    44         """ Test adapters' setters """ 
    45         adapter = IGEOLocated(self.page) 
    46         adapter.setLatitude(LATITUDE) 
    47         adapter.setLongitude(LONGITUDE) 
    48         self.failUnlessEqual(self.adapter.geolocation['latitude'], LATITUDE) 
    49         self.failUnlessEqual(self.adapter.geolocation['longitude'], LONGITUDE) 
    50  
    51     def testSetLocationMethod(self): 
    52         """ Test setLocation adapters' method """ 
    53         IGEOLocated(self.page).setLocation(LATITUDE, LONGITUDE) 
    54         self.failUnlessEqual(self.adapter.geolocation['latitude'], LATITUDE) 
    55         self.failUnlessEqual(self.adapter.geolocation['longitude'], LONGITUDE) 
     39        self.failUnlessEqual(self.adapter.coordinates[0], LONGITUDE) 
     40        self.failUnlessEqual(self.adapter.coordinates[1], LATITUDE) 
     41        self.failUnlessEqual(self.adapter.coordinates[2], ALTITUDE) 
    5642 
    5743class TestGEOMapAdapter(PloneTestCase.PloneTestCase): 
  • geolocation/branches/crchemist-geo_refactoring/tests/testFunctional.py

    r721 r722  
    3434                                     'maptype'      : MAP_TYPE}, "POST") 
    3535        self.failUnlessEqual(response.getStatus(), 200) # OK 
    36         self.failUnlessEqual(IGEOLocated(self.page).getLatitude(), LATITUDE, 
     36        self.failUnlessEqual(IPoint(self.page).coordinates[1], LATITUDE, 
    3737                             "save_location.cpy script work incorrectly") 
    3838        self.failUnlessEqual(IGEOMap(self.page).getMapCenter(), MAP_CENTER,