[Zope3-Users] Extending IImage

FB fbo2 at gmx.net
Fri Nov 10 08:42:37 EST 2006


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


More information about the Zope3-users mailing list