[Zope3-Users] Extending IImage

Nordmann Arne arne.nordmann at uni-dortmund.de
Fri Nov 10 04:32:13 EST 2006


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".

 

I would appreciate every hint showing me why I'm off the mark. Thanks in
advance,

 

Arne

 

PS: I'm 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=_(u"Title"),

    description=_(u"The image title."),

    default=u"",

    required=False)

 

  imagecaption = Text(

    title=_(u"Caption"),

    description=_(u"The 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"

      />

[...]

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.zope.org/pipermail/zope3-users/attachments/20061110/8dbe64ed/attachment.htm


More information about the Zope3-users mailing list