On Mon, 2006-03-20 at 19:02 -0500, Stephan Richter wrote:
> On Monday 20 March 2006 17:26, Thierry FLORAC wrote:
> > Actually, the only working way I found to update my annotations through
> > my adapters is always to use "form" directives with the help of a
> > support class using "getData/setData" methods which call the adapter
> > directly...
> 
> Can you post the code again, the one that is not working? Note that a 
> persistent dict is no good, since the form code tries to set an attribute and 
> not a mapping item.

You will find a copy of my previous post below.
I just hope I didn't forgot anything...

Thanks for any help,

  Thierry

---------------------------------------------------------------------

I've started to work a little more on this problem, and got a few
improvements but still a few "problems". In fact :
 - I can create my main content component correctly
 - I can see the adapter's "view form" into ZMI
 - I can select this view ; an empty annotations "PersistentDict" is
then immediately created as requested
 - but I can't update adapter's interface's properties : the "setData"
method is called, but the properties methods are not called when
"setData" is called. No error is displayed, and the form just display
request values that are "removed" as soon as the view is refreshed...

My code is in fact very simple :

    class IPhotoStorage:
        identifier = TextLine(...)
        hostname = TextLine(...)
        
    PhotoStorageKey = "http://www.ulthar.net/keys/storage";
        
    class PhotoStorage:
        implements(IPhotoStorage)
        adapts(IPhoto)
        
        def __init__ (self, context):
            self.context = self.__parent__ = context
            annotations = IAnnotations(context)
            data = annotations.get(PhotoStorageKey)
            if data is None:
                data = annotations[PhotoStorageKey] = PersistentDict()
            self._data = data
        
        def _getIdentifier (self):
            return self._data.get('identifier',None)
        
        def _setIdentifier (self, identifier):
            self._data['identifier'] = unicode(identifier)
            notify(ObjectModifiedEvent(self.context))
        
        identifier = property(_getIdentifier, _setIdentifier)
        
        [...then same code for "hostname" property...]
        
    class PhotoStorageHandler(object):
        
        def getData(self):
            result = {}
            result['identifier']= IPhotoStorage(self.context).identifier
            result['hostname'] = IPhotoStorage(self.context).hostname
            return result
        
        def setData(self, data):
            IPhotoStorage(self.context).identifier = data['identifier']
            IPhotoStorage(self.context).hostname = data['hostname']
            return u"Saved changes"
        

And here is my "main" configure.zcml part for the adapter :

        <adapter
                factory=".photo.PhotoStorage"
                provides=".interfaces.IPhotoStorage"
                for=".interfaces.IGalleryPhoto"
                trusted="true" />
        
        <class class=".photo.PhotoStorage">
                <require
                        permission="zope.View"
                        interface=".interfaces.IPhotoStorage" />
                <require
                        permission="zope.ManageContent"
                        set_schema=".interfaces.IPhotoStorage" />
        </class>

and finally my "browser" configure.zcml :

        <form
                name="storage.html"
                for=".interfaces.IGalleryPhoto"
                schema=".interfaces.IPhotoStorage"
                class=".forms.PhotoStorageHandler"
                fields="identifier hostname"
                label="Storage"
                permission="zope.ManageContent"
                menu="zmi_views" title="Storage" />

A few "print" instructions show that :
 - PhotoStorageHandler.setData is called correctly, but
 - PhotoStorage._setIdentifier is NOT called when setting "identifier"
property



-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.

_______________________________________________
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users

Reply via email to