[Zope-CMF] Re: How-To: Automatically Add Objects at CMF
Member Creation Time
Grégoire Weber
gregoire.weber@switzerland.org
Tue, 21 Aug 2001 00:26:52 +0200
Hi Norman,
> I'll try this out. Also is it possible to have the default_member_content
> listing to be a proformatted html file instead of being a structured test,
> so that if I create a template.dtml then the can I call it somehow within
> the default_member_content = template.dtml ?
>
> Does this make sense?
As you can see in the add menu when you are viewing the members directory
content, you can choose between HTML and structured text. If you look at the
code of 'document_edit_form' you can see the correct parameters for HTML
and structured text. See also remark 2) below.
Yes, it makes (even more) sense to have the pages content in a own file!
It works the same way as in the image example. So the whole code is
(untested)::
# 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 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()
remarks:
1) The name of the file in the products folder is independant of the name of
the file in the ZODB. But it is wise to not choose different names! Take
the same name and add a '.dtml' to it and put it in a own subdirectory
named 'dtml' (both not necessary, but as it seems a usefull convention).
2) possible formats: "html" and "structured-text"
3) I don't know how good you're in Python, so I give a short explanation
about this:
- If you want to include the same html file for every user use filedata
- If you want to insert the members login name into the file use
(filedata % id). In this case there has to be one %s format string
in the index_html.dtml file data. e.g.::
<h1>Congratulations %s!</h1>
<p>You've successfully joined blabla ...</p>
If you encounter problems or have further questions please insert the code
snippet causing problems in your e-mail.
Do you know about programming in Python?
In future please cc: the cmf-mailing list. There are a lot of people there
with even more zope zen possibly supplying you (and me) with more elegant
solutions.
Greg
_____________________________________
Grégoire Weber
mailto:gregoire.weber@switzerland.org