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

Tres Seaver tseaver@palladion.com
Thu, 02 Aug 2001 21:02:52 -0400


Grégoire Weber wrote:

> Thanks for your advice, Tres!
> 
> You took me to the right way. It even worked after changing a 
> small detail...
> 
> I had to set 'portal_type' to 'Image' instead of setting it to 
> 'Portal Image'! That's it!
> 
> Zope's XML exporting functionality is cool! I came behind this 
> by adding an additional image manualy and exporting both in 
> XML to search for differences. :-)
> 
> 
>>You need to get the 'portal_type' label of your image set, as
>>the stock 'invokeFactory' mechanism does.
>>
>>Add this::
>>
>>     image = f._getOb( 'org_logo' )
>>     image.portal_type = 'Portal Image' # the ID of the type object
>>
> 
> You're talking about the similar code parts in 'constructInstance' in 
> TypesTool.py I suppose.
> 
> So I finaly use the following working code to instanate a Portal 
> Image which seems to me to be "more compatible" (just for the 
> archive searchers on the list)::
> 
>     # Create default logo.
>     fileobj = open(os.path.join(product_path, 'img', 'earthsmile.gif'), 'rb')
>     filedata = fileobj.read()
> 
>     Image.addImage(f,
>                    'org_logo',
>                    title = '%s Home' % member_id,
>                    file = filedata,
>                    format = 'image/gif')
>     ob = f._getOb( 'org_logo' )
>     if hasattr(ob, '_setPortalTypeName'):
>         ob._setPortalTypeName('Image')
> 
>     fileobj.close()
> 
> Remaining question (answer mandatory):
> 
>    Why is this not necessary for the instanation of the 'index_html' 
>    Document in 'createMemberarea' of 'CMFDefault/MembershipTool.py'?


Yes, it should be changed, as it sets a bad example.  The reason it

works anyway is that the 'meta_type' of the CMFDefault.Document.Document
class aligns with the ID of the type object ('Document');  for images,
the 'meta_type' is 'Portal Image', while the ID of the type object is
'Image'.  Here is the diff for the change I am about to check in:

diff -u -r1.10 MembershipTool.py
--- CMFDefault/MembershipTool.py	13 Jun 2001 18:02:14 -0000	1.10
+++ CMFDefault/MembershipTool.py	3 Aug 2001 00:59:41 -0000
@@ -178,6 +178,7 @@
              user = acl_users.getUser(member_id).__of__(acl_users)
              f.changeOwnership(user)
              f.manage_setLocalRoles(member_id, ['Owner'])
+            f._setPortalTypeName( 'Document' )

              # Create Member's home page.
              # default_member_content ought to be configurable per


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