[Zope-CMF] A 'Portal Image' added programaticaly behaves different than a manualy added one

Tres Seaver tseaver@palladion.com
Thu, 2 Aug 2001 15:11:12 -0400 (EDT)


On Thu, 2 Aug 2001, [iso-8859-1] Gr=E9goire Weber wrote:

> Hi everybody!
>=20
> If I add a CMF image programaticaly, it does not behave like one=20
> added manualy through the CMF by pressing 'Add...' in folder contents.
>=20
> If I want to view the image by=20
>=20
>    http://localhost:8080/up/Members/gugus/org_logo/view
>=20
> I get the following error
>=20
>    Not Found: Cannot find default view for "/up/Members/gugus/org_logo"
>=20
>    Traceback (innermost last):
>      File D:\prog\zope\lib\python\ZPublisher\Publish.py, line 223, in
> publish_module
>      File D:\prog\zope\lib\python\ZPublisher\Publish.py, line 187, in pub=
lish
>      File D:\prog\zope\lib\python\Zope\__init__.py, line 221, in
> zpublisher_exception_hook
>        (Object: org_logo)
>      File D:\prog\zope\lib\python\ZPublisher\Publish.py, line 171, in pub=
lish
>      File D:\prog\zope\lib\python\ZPublisher\mapply.py, line 160, in mapp=
ly
>        (Object: view)
>      File D:\prog\zope\lib\python\ZPublisher\Publish.py, line 112, in
> call_object
>        (Object: view)
>      File F:\user\greg\data\zope\Products\CMFCore\PortalContent.py, line
> 247, in view
>        (Object: org_logo)
>      File F:\user\greg\data\zope\Products\CMFCore\PortalContent.py, line
> 234, in __call__
>        (Object: org_logo)
>      File F:\user\greg\data\zope\Products\CMFCore\PortalContent.py, line
> 227, in _getDefaultView
>        (Object: org_logo)
>    Not Found: (see above)

You need to get the 'portal_type' label of your image set, as
the stock 'invokeFactory' mechanism does.
=20
>=20
> In contrast http://localhost:8080/up/Members/gugus/org_logo correctly=20
> shows the image.
>=20
>=20
> The code::
>=20
>    product_path =3D os.path.join(Globals.package_home(globals()))
>    fileobj =3D open(os.path.join(product_path, 'img', 'earthsmile.gif'), =
'rb')
>    filedata =3D fileobj.read()
>    Image.addImage(f,
>                   'org_logo',
>                   title =3D '%s Home' % member_id,
>                   file =3D filedata,
>                   format =3D 'image/gif')
>    fileobj.close()

Add this::

     image =3D f._getOb( 'org_logo' )
     image.portal_type =3D 'Portal Image' # the ID of the type object
=20
> Some additional informations
>=20
>    - I'm able to view the metadata edit form, but I can't save the change=
s
>      (http://localhost:8080/up/Members/gugus/org_logo/metadata_edit_form)=
=2E
>      I get the following error:
>=20
>         AttributeError: 'None' object has no attribute 'getActionById'=20
>=20
>    - In the ZMI the images icon looks like a DTML Document !!! hm?
>=20
> I do this in the context of createMemberarea which I hotfixed (works well=
)=20
> to put a default logo into the members folder after creation of the=20
> member folder.
>=20
> I'am using CMF 1.1 on Zope 2.3.3 on WinNT4SP6
>=20
> What's (obviously) wrong?=20
> Hints helping me to find a way to solve the problem myself also appreciat=
ed.

Tres.
--=20
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
Tres Seaver                                tseaver@zope.com
Zope Corporation      "Zope Dealers"       http://www.zope.com