[Zope3-Users] Newbie question...

Thierry FLORAC tflorac at ulthar.net
Mon Mar 6 19:20:31 EST 2006


On Sat, 2006-03-04 at 16:01 +0100, Thierry FLORAC wrote:
> I've started to create a few components with Zope-3.2.
> Until now, everything is OK for simple content components and a few
> utilities.
> 
> I'm actually trying to develop new adapters.
> One of these adapters is designed to use annotations, but I can't make
> it working in Zope3 management interface : page link is displayed
> correctly, in my "editform" properties provided by my interface are
> displayed and modified apparently correctly, but introspector show
> that these properties are stored as "simple" attributes and not as
> annotations ; adapter's code is never called !
> I've probably missed something, so here are the steps I followed :
> - create custom interface => OK
> - create adapter => apparently OK
> - define adapter in main "configure.zcml" file => OK
> - define "editform" in browser's "configure.zcml" => probably bad !

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(ObjectAnnotationsModifiedEvent(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" />


Of course, a good help would be really welcome...
Many thanks,

  Thierry



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



More information about the Zope3-users mailing list