[Zope3-Users] Extending IImage
Hi guys, Im trying to extend the Interface IImage by a title and a caption. My plan was to use zope.app.file.interfaces.IImage as base interface and zope.app.file.Image as base class, but that doesnt work. Every time I submit the add form, I get the following traceback: [] File C:\Python24\Lib\site-packages\zope\tales\tales.py, line 696, in evaluate return _expression_(self) File C:\Python24\Lib\site-packages\zope\tales\expressions.py, line 205, in __call__ return self._eval(econtext) File C:\Python24\Lib\site-packages\zope\tales\expressions.py, line 199, in _eval return ob() File C:\Python24\Lib\site-packages\zope\app\form\browser\add.py, line 62, in update self.createAndAdd(data) File C:\Python24\Lib\site-packages\zope\app\form\browser\add.py, line 120, in createAndAdd field.set(adapted, data[name]) File C:\Python24\Lib\site-packages\zope\schema\_bootstrapfields.py, line 183, in set setattr(object, self.__name__, value) File C:\Python24\Lib\site-packages\zope\security\checker.py, line 488, in check_setattr self._checker2.check_setattr(object, name) ForbiddenAttribute: ('contentType', pr.image.image.CustomImage object at 0x02FB8CB0) Whats the problem? Why is contentType forbidden? Data and contentType are valid attributes of the base interface zope.app.file.interfaces.IImage. I would appreciate every hint showing me why Im off the mark. Thanks in advance, Arne PS: Im working on Zope 3.3 and Python 2.4. The following lines show the interface, the class and the zcml-directives for the add form. Interfaces.py: from zope.app.file.interfaces import IImage class ICustomImage(IImage): imagetitle = TextLine( title=_(uTitle), description=_(uThe image title.), default=u, required=False) imagecaption = Text( title=_(uCaption), description=_(uThe image caption. Will be displayed in the user view. ), default=u, required=False) image.py: from zope.app.file import Image from pr.image.interfaces import ICustomImage class CustomImage(Image): implements(ICustomImage) title = u'' description = u'' def __init__(self, data='', title='', caption=''): super(Image, self).__init__(data) self.imagetitle = title self.imagecaption = caption configure.zcml: [] addform label=Add customized image name=AddCustomImage.html schema=pr.image.interfaces.ICustomImage content_factory=pr.image.image.CustomImage fields=contentType data imagetitle imagecaption permission=zope.ManageContent / addMenuItem class=pr.image.image.CustomImage title=Customized image description=A customized image permission=zope.ManageContent view=AddCustomImage.html / [] ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
Re: [Zope3-Users] Extending IImage
Hi, On Fri, Nov 10, 2006 at 10:32:13AM +0100, Nordmann Arne wrote: Hi guys, I'm trying to extend the Interface IImage by a title and a caption. My plan was to use zope.app.file.interfaces.IImage as base interface and zope.app.file.Image as base class, but that doesn't work. Every time I submit the add form, I get the following traceback: [...] File C:\Python24\Lib\site-packages\zope\tales\tales.py, line 696, in evaluate return expression(self) File C:\Python24\Lib\site-packages\zope\tales\expressions.py, line 205, in __call__ return self._eval(econtext) File C:\Python24\Lib\site-packages\zope\tales\expressions.py, line 199, in _eval return ob() File C:\Python24\Lib\site-packages\zope\app\form\browser\add.py, line 62, in update self.createAndAdd(data) File C:\Python24\Lib\site-packages\zope\app\form\browser\add.py, line 120, in createAndAdd field.set(adapted, data[name]) File C:\Python24\Lib\site-packages\zope\schema\_bootstrapfields.py, line 183, in set setattr(object, self.__name__, value) File C:\Python24\Lib\site-packages\zope\security\checker.py, line 488, in check_setattr self._checker2.check_setattr(object, name) ForbiddenAttribute: ('contentType', pr.image.image.CustomImage object at 0x02FB8CB0) What's the problem? Why is contentType forbidden? Data and contentType are valid attributes of the base interface zope.app.file.interfaces.IImage. You need a seperate class ...-Statement for any class - no matter, which interface(s) it provides. The require-attribute 'like_class' might come handy... However - I've had your problem to (needed to provide 'alt' and 'description'- img-attributes to be XHTML-compliant...). The solution is rather simple: * dc=IZopeDublinCore(myimageobject) (see zope.dublincore) * title-information is in dc.title * caption is in dc.description * an additional view 'longdesc.txt' for IImage provides content of dc.description as plain text img tal:attributes=src context/@@absolute_url; longdesc string:${context/@@absolute_url}/longdesc.txt alt=title / This way you can use original image-class. HTH, Frank ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
Re: [Zope3-Users] Extending IImage
On Fri, Nov 10, 2006 at 02:42:37PM +0100, FB wrote: You need a seperate class ...-Statement for any class - no matter, which interface(s) it provides. The require-attribute 'like_class' might come handy... Sorry for my poor english: for any class is wrong. Correct is for *every* class. Regards, Frank ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
RE: [Zope3-Users] Extending IImage
Hi Frank, thank you. That's a really good idea to save time and work. It seems to work very well. Kindly, Arne ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users