Changeset 1228

Show
Ignore:
Timestamp:
11/14/07 14:53:30 (1 year ago)
Author:
sgillies
Message:

Improve clarity of geoItems method and add logging (#339)

Files:

Legend:

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

    r1227 r1228  
    3535from Products.ATContentTypes.interface.topic import IATTopic 
    3636from Products.ATContentTypes.interface.folder import IATFolder 
     37from Products.ATContentTypes.interface.folder import IATBTreeFolder 
    3738 
    3839from Products.PleiadesGeocoder.interfaces import IGeoItemSimple \ 
    3940    , IGeoCollectionSimple, IGeoreferencedEvent 
     41 
     42import logging 
     43 
     44logger = logging.getLogger('PleiadesGeocoder.geo') 
    4045 
    4146 
     
    158163        if IATTopic.providedBy(self.context): 
    159164            for ob in self.context.queryCatalog(): 
    160                 try: 
    161                     item = IGeoItemSimple(ob.getObject()) 
    162                     assert(item.isGeoreferenced()) 
    163                 except
     165                item = self._adapt(ob.getObject()) 
     166                if item is not None: 
     167                    yield item 
     168                else
    164169                    continue 
     170        elif (IATFolder.providedBy(self.context) or 
     171              IATBTreeFolder.providedBy(self.context)): 
     172            for ob in self.context.listFolderContents(): 
     173                item = self._adapt(ob) 
     174                if item is not None: 
     175                    yield item 
     176                else: 
     177                    continue 
     178        # Last resort: single objects may yield geoItems 
     179        else: 
     180            item = self._adapt(self.context) 
     181            if item is not None: 
    165182                yield item 
    166         elif IATFolder.providedBy(self.context):  
    167             for ob in self.context.listFolderContents(): 
    168                 try: 
    169                     item = IGeoItemSimple(ob) 
    170                     assert(item.isGeoreferenced()) 
    171                 except: 
    172                     continue 
    173                 yield item 
    174         else: 
    175             try: 
    176                 item = IGeoItemSimple(self.context) 
    177                 assert(item.isGeoreferenced()) 
    178             except: 
    179                 pass 
    180             yield item 
     183 
     184    def _adapt(self, ob): 
     185        try: 
     186            item = IGeoItemSimple(ob) 
     187            if item.isGeoreferenced(): 
     188                return item 
     189            else: 
     190                logger.debug("%s is not georeferenced" % item) 
     191        except TypeError: 
     192            logger.debug("Could not adapt %s to IGeoItemSimple" % self.context) 
     193        return None 
    181194 
    182195