Re: "Object is of wrong type" with NamedBlogImage field

Timo Stollenwerk <tisto-z4DKO/[email protected]>
Newsgroups gmane.comp.web.zope.plone.user
Message-ID <[email protected]>
Am 16.09.2014 um 11:24 schrieb Andreas Jung:
> Plone 4.3, Dexterity 2.
> 
> I have an image field
> 
>     image = NamedBlobImage(
>        title=_(u'label_special_image'),
>        description=_(u'help_special_image'),
>        required=False,
>     )
> 
> which is updated during a migration using
> 
>                 if new_obj.portal_type == 'Image':
>                     setattr(new_obj, k, namedfile.NamedBlobImage(v,
> filename=filename))
> 
> 
> The image is stored correctly and shown correctly in our own custom
> view. When we @@edit the content-type instance and save then we
> receive an error "Object is of wrong type" (see screenshot).
> The preview of the image is also being displayed correctly.
> 
> Why is this happening?

This usually happens when the attribute object type is not stored
correctly. Everything works, just the form validators complain.

Here is how I usually set a NamedBlobImage in a test:

    self.portal.mi.eb.invokeFactory('grafik', 'text1')
    image_file = os.path.join(os.path.dirname(__file__), u'logo.jpg')
    self.portal.mi.eb.text1.grafik = NamedBlobImage(
        data=open(image_file, 'r').read(),
        contentType='image/jpg',
        filename=u'logo.jpg'
    )

Hope that helps...
Timo

------------------------------------------------------------------------------
Want excitement?
Manually upgrade your production database.
When you want reliability, choose Perforce.
Perforce version control. Predictably reliable.
http://pubads.g.doubleclick.net/gampad/clk?id=157508191&iu=/4140/ostg.clktrk
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.