Log in |
Automatically Add Objects at CMF Member Creation TimeAbstractThis How-To covers how to add default objects to a newly created members My Stuff area programmatically. This How-To describes how doing this by hotfixing the CMFDefault/MembershipTool class. This is only one way how to do it. Decide on your own if you like the hotfix method. Have also a look at Casey Duncan's How-To about hotfixing Zope. Introduction Every time a new member area is created the
The actual CMF (version 1.1, newer versions
will possibly allow this by the click and
pray :-) adds a Hotfixing a CMF Class Method (is easy!) We replace the whole This way your customization is independant*) from the rest of the CMF code and you won't loose your changes by installing new versions of the CMF. *) Ok, it doesn't give you 100% independancy. If the code in MembershipTool changes totaly it possibly breaks your hotfix and then you possibly have to adapt the changes in MembershipTool. Seven Steps to Heaven
Customizing the hotfix product Now customize the part between
The type names of objects other than the
images one can be viewed under
__init__.pyThe code:
""" Hotfix with altered createMemberarea
"""
import os
import Globals
from Products.CMFDefault.MembershipTool import MembershipTool
from Products.CMFDefault import Image
# 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')
# ----- end object instanations -----
# Overcome an apparent catalog bug.
f.org_logo.reindexObject()
MembershipTool.createMemberarea = createMemberarea
Update 01.03.2003 (Thanks to Colin Leath):for a TTW method to achieve the same thing, visit: http://www.zopelabs.com/cookbook/1046292285 About this documentThis document will not be kept in-sync with the latest Zope CMF version by the current maintainer. Version
AuthorGrégoire Weber zope@i-con.ch Current MaintainerSend questions and patches to Grégoire Weber zope@i-con.ch |