[Zope-CMF] Re: How-To: Automatically Add Objects at CMF Member Creation Time
Norman Khine
norman@khine.net
Tue, 21 Aug 2001 04:03:05 +0100
Hi Greg,
I looked into both sources and tried to make this work both ways, first:
I modified the CMFDefault/MembershipTool.py, by replacing, the original
entry for the creation of the index_html with:-
# 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"
, "structured-text"
, (filedata % id)
)
# give the image the correct portal type
ob = f._getOb( 'org_logo' )
if hasattr(ob, '_setPortalTypeName'):
ob._setPortalTypeName('Document')
# Overcome an apparent catalog bug.
f.index_html.reindexObject()
but got an error on restarting the server
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
9 times
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?
my index_html.dtml file is in CMFDefaultHotfix/dtml/ directory and
newtons.gif is in CMFDefaultHotfix/img/ directory
index_html.dtml
<h1>Congratulations %s!</h1>
<p>You've successfully joined blabla ...</p>
<img src="pic.gif" />
Thanks
Norman
CMFDefaultHotfix/__init__.py
""" 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', 'newtons.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()
# 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' # 1)
, member_id+"'s Home"
, member_id+"'s front page"
, "structured-text" # 2)
, (filedata % id) # 3)
)
# give the index_html the correct portal type
obj = f._getOb( 'index_html' )
if hasattr(obj, '_setPortalTypeName'):
obj._setPortalTypeName('Document')
# Overcome an apparent catalog bug.
f.index_html.reindexObject()