[Zope3-Users] What is a "locatable" adapter ?

Thierry Florac thierry.florac at onf.fr
Mon Nov 20 12:26:13 EST 2006


  Hi,

I have a little question for a problem that I'm going to describe as
much as possible via a few code samples...

interfaces.py::

        class IAlertInfo(Interface):
            """Alert target management"""
            
            frequency = Choice(title=_("Alert frequency"),
                                     required=False,
                                     vocabulary=alert_type_vocabulary)
        
            comments = Text(title=_("Alert's comments"),
                                  required=False,
                                  default=u'')
            
            last_date = Date(title=_("Last alert date"),
                                   required=False)
            
        class IAlertInfoWriter(Interface):
            """Alert management interface"""
            
            def alert(alert_date=None):
                """Launch alert to content's owner"""
        
        class IAlert(IAlertInfo, IAlertInfoWriter):
            """Marker interface for alerts"""
        
        class IAlertTarget(Interface):
            """Marker interface to identify alertable contents"""

alert.py::

        AlertStorageKey = "onf.component.alert"
        
        class AlertAdapter(object):
            """Adapter used to adapt IAlertTarget objects to
        IAlertInfo"""
        
            implements(IAlertInfo)
            
            def __init__(self, context, request=None):
                self.context,self.request = context,request
                annotations = IAnnotations(context)
                data = annotations.get(AlertStorageKey)
                if data is None:
                    data = annotations[AlertStorageKey] =
        PersistentDict()
                self._data = data
                
            def _getFrequency(self):
                return self._data.get('frequency', None)
            
            def _setFrequency(self, frequency):
                self._data['frequency'] = frequency
                
            frequency = property(_getFrequency, _setFrequency)
            
            def _getComments(self):
                return self._data.get('comments', None)
            
            def _setComments(self, comments):
                self._data['comments'] = uninvl(comments)
            
            comments = property(_getComments, _setComments)
            
            def _getLastAlert(self):
                return self._data.get('last_alert', None)
            
            def _setLastAlert(self, alert_date=None):
                if alert_date is None:
                    alert_date = datetime.now()
                self._data['last_alert'] = alert_date
        
            last_date = property(_getLastAlert, _setLastAlert)
            
            def alert(self):
                """Send message to owners"""
                owner = IOwner(self.context).owner
        
configure.zcml::

    <adapter
        factory=".alert.AlertAdapter"
        provides=".interfaces.IAlert"
        for=".interfaces.IAlertTarget"
        trusted="true"
        locate="true" />
    
    <class class=".alert.AlertAdapter">
        <require
            interface=".interfaces.IAlertInfo"
            permission="zope.View" />
        <require
            set_schema=".interfaces.IAlertInfo"
            permission="onf.ManageContent" />
        <require
            interface=".interfaces.IAlertInfoWriter"
            permission="onf.ManageServices" />
    </class>


My question is just that without "locate=true" attribute in
"configure.zcml", I can't make my adapter working and I always get
"unhautorized" exceptions as soon as I try to modify a property throught
my adapter, even if the required permission (onf.ManageContent) is
correctly granted on the adapter context.
So it seems to work with it, but I'd really like to know why...

Thanks for any information...

  Thierry Florac
-- 
  Chef de projet intranet/internet
  Office National des Forêts - Département Informatique
  2, Avenue de Saint-Mandé
  75570 PARIS Cedex 12
  Mél : thierry.florac at onf.fr
  Tél. : +33 01.40.19.59.64
  Fax. : +33 01.40.19.59.85



More information about the Zope3-users mailing list