Changeset 1325

Show
Ignore:
Timestamp:
05/28/08 12:40:13 (6 months ago)
Author:
sgillies
Message:

Raise unlocated exception earlier when adapting

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • PleiadesEntity/trunk/geo.py

    r1307 r1325  
    7070        """Initialize adapter.""" 
    7171        self.context = context 
    72  
    73     @property 
    74     def primary_location(self): 
     72        self._adapter = None 
    7573        x = self.context.getRefs('hasLocation') 
    7674        if len(x) == 0: 
    77             return None 
     75            raise Exception, "Unlocated: could not adapt %s" % str(context) 
    7876        else: 
    79             return IGeoreferenced(x[0]) 
     77            self._adapter = IGeoreferenced(x[0]) 
    8078 
    8179    @property 
    8280    def type(self): 
    83         return self.primary_location.type 
     81        return self._adapter.type 
    8482 
    8583    @property 
    8684    def coordinates(self): 
    87         return self.primary_location.coordinates 
    88         # 
    89         #x = self.context.getRefs('hasLocation') 
    90         #if len(x) == 0: 
    91         #    return () 
    92         #x0 = x[0] 
    93         #values = [float(v) for v in \ 
    94         #    x0.getSpatialCoordinates().split()] 
    95         #nvalues = len(values) 
    96         # Our Pleiades Locations are 2D 
    97         #npoints = nvalues/2 
    98         #coords = [] 
    99         #for i in range(npoints): 
    100         #    #coords.append(tuple(values[3*i:3*i+3] + [0.0])) 
    101         #    coords.append((values[3*i+1], values[3*i], 0.0)) 
    102         #return coords[0] 
     85        return self._adapter.coordinates 
    10386 
    10487    @property 
     
    11295            type='Feature', 
    11396            id=context.getId(), 
    114             geometry=self.primary_location.__geo_interface__ 
     97            geometry=self._adapter.__geo_interface__ 
    11598            ) 
    11699 
     
    125108        """Initialize adapter.""" 
    126109        self.context = context 
    127         self._primary_association = None 
     110        self._adapter = None 
    128111        for ob in self.context.values(): 
    129112            try: 
    130                 self._primary_association = IGeoreferenced(ob) 
     113                self._adapter = IGeoreferenced(ob) 
    131114            except: 
    132115                continue 
    133116            break 
    134         if not self._primary_association
     117        if not self._adapter
    135118            raise Exception, "Could not adapt %s" % str(context) 
    136119 
    137120    @property 
    138121    def type(self): 
    139         return IGeoreferenced(self._primary_association).type 
     122        return IGeoreferenced(self._adapter).type 
    140123 
    141124    @property 
    142125    def coordinates(self): 
    143         return IGeoreferenced(self._primary_association).coordinates 
     126        return IGeoreferenced(self._adapter).coordinates 
    144127 
    145128    @property 
     
    149132    @property 
    150133    def __geo_interface__(self): 
    151         return IGeoreferenced(self._primary_association).__geo_interface__ 
     134        return IGeoreferenced(self._adapter).__geo_interface__ 
     135 
    152136 
    153137def createGeoItem(context): 
     
    157141    else: 
    158142        return PlacefulAssociationGeoItem(context) 
    159  
    160  
    161