[Zope-CMF] Re: How-To: Automatically Add Objects at CMF Member Creation Time

Norman Khine khine@btinternet.com
Tue, 21 Aug 2001 17:51:24 +0100


Thanks Greg,
This worked a treat, I will do a bit more testing and report back to the
list.

Regards

Norman

-----Original Message-----
From: zope-cmf-admin@zope.org [mailto:zope-cmf-admin@zope.org]On Behalf
Of Grégoire Weber
Sent: 21 August 2001 10:07
To: Norman Khine
Cc: zope-cmf@zope.org; josh@pdxbands.com
Subject: RE: [Zope-CMF] Re: How-To: Automatically Add Objects at CMF
Member Creation Time


Hi Norman,

> 2001-08-21T01:13:12 ERROR(200) ZODB Couldn't load state for
> '\x00\x00\x00\x00\x00\x00|B'
> Traceback (innermost last):
>   File /usr/home/dsuk5/zope/2.4.0/lib/python/ZODB/Connection.py, line 544,
> in setstate
> SystemError: Failed to import class _ZClass_for_DefaultDublinCoreImpl from
> module Products.CMFDefault

Hm, here I can't help!

Errors in 'createMemberarea' normaly get generated upon the first time
somebody joins your portal and not upon Zope startup.

If the above problem persists you probably have changed some of the code
you didn't want. If it is the case install the CMF another time to be sure
to have an unaltered code base.

> So, reinstalling the original MemebrshipTool.py and adding the file
creation
> to the CMFDefaultHotfix __init__.py, which is listed below.
>
> Thinking this will overide the existing index_html creation and pull in
the
> file I have created in the CMFDefaultHotfix/dtml/index_html.dtml
>
> but it does not, this brings the original index_html file created by the
> MembershipTool.py, what am I doing wrong?

I tested the code I sent to you and it works after some small corrections
indicated by ###:

""" Hotfix with altered createMemberarea
"""

import os

import Globals

from Products.CMFDefault.MembershipTool import MembershipTool
from Products.CMFDefault import Image, Document ### added Document import

# get the path of the Products folder
product_path = os.path.join(Globals.package_home(globals()))

def createMemberarea(self, member_id):
    """
    create a member area
    """
    parent = self.aq_inner.aq_parent
    members =  getattr(parent, 'Members', None)

    if members is not None and not hasattr(members, member_id):
        members.manage_addPortalFolder(member_id)
        f=getattr(members, member_id)

        # Grant ownership to Member
        acl_users = self.acl_users
        if not hasattr(acl_users, 'getUsers'):
            # This hack works around the absence of getUsers() in
LoginManager.
            # Gets the PersistentUserSource object that stores our users
            for us in acl_users.UserSourcesGroup.objectValues():
                if us.meta_type == 'Persistent User Source':
                    acl_users = us.__of__(acl_users)
                    break

        user = acl_users.getUser(member_id).__of__(acl_users)
        f.changeOwnership(user)
        f.manage_setLocalRoles(member_id, ['Owner'])

        # ----- begin object instanations -----
        # Create default logo: open and read 'earthsmile.gif' in
'Products/img'
        fileobj = open(os.path.join(product_path, 'img', 'earthsmile.gif'),
'rb')
        filedata = fileobj.read()
        fileobj.close()

        # instanate a Image with the name 'org_logo'
        Image.addImage(f,
                       'org_logo',
                       title = '%s Home' % member_id,
                       file = filedata,
                       format = 'image/gif')

        # give the image the correct portal type
        ob = f._getOb( 'org_logo' )
        if hasattr(ob, '_setPortalTypeName'):
            ob._setPortalTypeName('Image')

        # Overcome an apparent catalog bug.
        f.org_logo.reindexObject()

        # Create index_html: open and read 'index_html.dtml' from
'Products/dtml'
        fileobj = open(os.path.join(product_path, 'dtml',
'index_html.dtml'), 'r')
        filedata = fileobj.read()
        fileobj.close()

        # Create Member's home page.
        # default_member_content ought to be configurable per
        # instance of MembershipTool.
        Document.addDocument( f
                            , 'index_html'
                            , member_id+"'s Home"
                            , member_id+"'s front page"
                            , "html"
                            , (filedata % member_id) ### changed id to
member_id
                            )
        # give the image the correct portal type
        ob = f._getOb( 'index_html' )   ### there was org_log instead of
index_html
        if hasattr(ob, '_setPortalTypeName'):
            ob._setPortalTypeName('Document')
        # Overcome an apparent catalog bug.
        f.index_html.reindexObject()

        # ----- end object instanations -----


MembershipTool.createMemberarea = createMemberarea


The index_html.dtml file:

<h1>Congratulations %s!</h1>
<p>You've successfully joined blabla ...</p>
<img src="org_logo" />

Greg
_____________________________________
Grégoire Weber
Rigistr. 31
CH-8006 Zürich
Switzerland
phone:  +41-(0)1-361 66 11
mobile: +41-(0)79-44 11 457
mailto:gregoire.weber@switzerland.org

_______________________________________________
Zope-CMF maillist  -  Zope-CMF@zope.org
http://lists.zope.org/mailman/listinfo/zope-cmf

See http://www.zope.org/Products/PTK/Tracker for bug reports and feature
requests