Changeset 722
- Timestamp:
- 01/03/07 07:47:41
- Files:
-
- geolocation/branches/crchemist-geo_refactoring/Extensions/Install.py (modified) (1 diff)
- geolocation/branches/crchemist-geo_refactoring/adapters/geolocation.py (modified) (2 diffs)
- geolocation/branches/crchemist-geo_refactoring/browser/location.py (modified) (2 diffs)
- geolocation/branches/crchemist-geo_refactoring/configure.zcml (modified) (2 diffs)
- geolocation/branches/crchemist-geo_refactoring/interfaces/geolocation.py (modified) (2 diffs)
- geolocation/branches/crchemist-geo_refactoring/tests/commonTestingStuff.py (modified) (2 diffs)
- geolocation/branches/crchemist-geo_refactoring/tests/runtests.sh (deleted)
- geolocation/branches/crchemist-geo_refactoring/tests/testAdapters.py (modified) (2 diffs)
- geolocation/branches/crchemist-geo_refactoring/tests/testFunctional.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
geolocation/branches/crchemist-geo_refactoring/Extensions/Install.py
r721 r722 68 68 out = StringIO() 69 69 out.write('setupSkin... \n') 70 setupSkin(self, out, PROJECTNAME) 70 setupSkin(self, out, PROJECTNAME) 71 71 catalog = getToolByName(self, 'portal_catalog') 72 72 if 'geoLocation' not in catalog.indexes(): geolocation/branches/crchemist-geo_refactoring/adapters/geolocation.py
r721 r722 1 1 from zope.interface import implements 2 from Products.geolocation.interfaces.geolocation import IGEOLocated2 from geo.interfaces import IPoint 3 3 from zope.app.annotation.interfaces import IAnnotations, IAnnotatable 4 4 from Products.CMFPlone.CatalogTool import registerIndexableAttribute … … 6 6 7 7 GEOLOCATION_KEY = "geolocation.adapters.geolocation" 8 9 class GEOLocated(object): 10 """ geolocation 11 """ 12 implements(IGEOLocated) 8 class Point(object): 9 implements(IPoint) 13 10 14 11 def __init__(self, context): 15 12 """ init """ 16 13 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: 19 16 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) 23 23 24 def getLongitude(self): 25 """ return longtitude """ 26 return self.geolocation['longitude'] 24 def getCoordinates(self): 25 return self.point['coordinates'] 27 26 28 def getLatitude(self): 29 """ return latitude """ 30 return self.geolocation['latitude'] 27 def setCoordinates(self, coordinates): 28 self.point['coordinates'] = coordinates 31 29 32 def setLongitude(self, value): 33 """ set longtitude """ 34 self.geolocation['longitude'] = float(value) 30 def getAltitudeMode(self): 31 return self.point['altitudeMode'] 35 32 36 def setLatitude(self, value): 37 """ set latitutde """ 38 self.geolocation['latitude'] = float(value) 33 def setAltitudeMode(self, altitudeMode): 34 self.point['altitudeMode'] = altitudeMode 39 35 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 """) 44 59 45 60 default = None 46 47 61 def geoLocation(obj, portal, **kw): 48 62 """ return the location list """ 49 63 if hasattr(obj.aq_base, 'geoLocation'): 50 64 return obj.geoLocation() 51 adapter = I GEOLocated(obj, None)65 adapter = IPoint(obj, None) 52 66 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: 56 69 return None 57 70 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 65 72 return default 66 73 67 def Latitude(obj, portal, **kw):68 adapter = IGEOLocated(obj, None)69 if adapter:70 return adapter.getLatitude()71 return default72 """73 74 registerIndexableAttribute('geoLocation', geoLocation) 74 #registerIndexableAttribute('Longitude', Longitude)75 #registerIndexableAttribute('Latitude', Latitude)geolocation/branches/crchemist-geo_refactoring/browser/location.py
r721 r722 6 6 7 7 # Product imports 8 from Products.geolocation.interfaces.geolocation import IGEOLocated, IGEOLocatedView 8 from geo.interfaces import IPoint 9 from Products.geolocation.interfaces.geolocation import IPointView 9 10 10 class GEOLocatedView(BrowserView):11 class PointView(BrowserView): 11 12 12 implements(I GEOLocatedView)13 implements(IPointView) 13 14 14 15 def __init__(self, context, request): … … 16 17 self.context = context 17 18 self.request = request 18 self.location = I GEOLocated(self.context, None)19 self.l atitude = self.location and self.location.getLatitude()or None20 self.l ongitude = self.location and self.location.getLongitude()or None19 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 21 22 22 23 def editLocation(self, latitude=None, longitude=None): 23 24 """ update location properties """ 24 self.location. setLocation(latitude, longitude)25 self.location.coordinates = (longitude, latitude,0) 25 26 self.context.reindexObject() 26 27 27 28 def getLatitude(self): 28 """ return locationlatitude """29 """ return point latitude """ 29 30 return self.latitude 30 31 31 32 def getLongitude(self): 32 """ return locationlongitude """33 """ return point longitude """ 33 34 return self.longitude geolocation/branches/crchemist-geo_refactoring/configure.zcml
r721 r722 21 21 <adapter 22 22 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" 25 25 /> 26 26 <adapter 27 27 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" 30 30 /> 31 31 <adapter 32 32 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" 35 35 /> 36 36 <adapter 37 37 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" 40 40 /> 41 41 <adapter 42 42 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" 45 45 /> 46 46 … … 82 82 for="*" 83 83 name="LocationView" 84 class=".browser.location. GEOLocatedView"84 class=".browser.location.PointView" 85 85 permission="cmf.ModifyPortalContent" 86 allowed_interface=".interfaces.geolocation.I GEOLocatedView"86 allowed_interface=".interfaces.geolocation.IPointView" 87 87 /> 88 88 geolocation/branches/crchemist-geo_refactoring/interfaces/geolocation.py
r721 r722 3 3 from zope.schema import Float 4 4 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): 5 class IPointView(Interface): 36 6 """browser view 37 7 """ … … 41 11 42 12 def getLatitude(): 43 """ return geolatitude """13 """ return point latitude """ 44 14 45 15 def getLongitude(): 46 """ return geolongitude """16 """ return point longitude """ geolocation/branches/crchemist-geo_refactoring/tests/commonTestingStuff.py
r721 r722 4 4 from Products.CMFCore.utils import getToolByName 5 5 6 from Products.geolocation.interfaces.geolocation import IGEOLocated, IGEOLocatedView 6 from geo.interfaces import IPoint 7 from Products.geolocation.interfaces.geolocation import IPointView 7 8 from Products.geolocation.interfaces.geomap import IGEOMap, IGEOMapView 8 from Products.geolocation.adapters.geolocation import GEOLocated9 from Products.geolocation.adapters.geolocation import Point 9 10 from Products.geolocation.adapters.geomap import GEOMap 10 from Products.geolocation.browser.location import GEOLocatedView11 from Products.geolocation.browser.location import PointView 11 12 from Products.geolocation.browser.map import GEOMapView 12 13 … … 37 38 LATITUDE = 2.3 38 39 LONGITUDE = 3.2 40 ALTITUDE = 2.1 39 41 MAP_CENTER = (9,9) 40 42 MAP_ZOOM = 6 geolocation/branches/crchemist-geo_refactoring/tests/testAdapters.py
r721 r722 13 13 def testAdapterInterface(self): 14 14 """ Test adapters' for intefaces """ 15 verifyClass(I GEOLocated, GEOLocated)15 verifyClass(IPoint, Point) 16 16 verifyClass(IGEOMap, GEOMap) 17 17 18 18 def testBrowserInterface(self): 19 19 """ Test browsers' for intefaces """ 20 verifyClass(I GEOLocatedView, GEOLocatedView)20 verifyClass(IPointView, PointView) 21 21 verifyClass(IGEOMapView, GEOMapView) 22 22 … … 28 28 self.folder.invokeFactory('Document', 'test_page') 29 29 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) 33 32 34 33 def testImplementation(self): 35 34 """ Test adapter implementation """ 36 I GEOLocated.implementedBy(GEOLocated)35 IPoint.implementedBy(Point) 37 36 38 37 def testGetters(self): 39 38 """ 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) 56 42 57 43 class TestGEOMapAdapter(PloneTestCase.PloneTestCase): geolocation/branches/crchemist-geo_refactoring/tests/testFunctional.py
r721 r722 34 34 'maptype' : MAP_TYPE}, "POST") 35 35 self.failUnlessEqual(response.getStatus(), 200) # OK 36 self.failUnlessEqual(I GEOLocated(self.page).getLatitude(), LATITUDE,36 self.failUnlessEqual(IPoint(self.page).coordinates[1], LATITUDE, 37 37 "save_location.cpy script work incorrectly") 38 38 self.failUnlessEqual(IGEOMap(self.page).getMapCenter(), MAP_CENTER,
