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

Norman Khine khine@btinternet.com
Wed, 22 Aug 2001 09:12:57 +0100


Hi Josh,
I think the crank of the matter is within the CMFDefaultHotfix __init__.py
file, where you must declare each method you want the generate, so in my
case where I wanted to add an external index_html and an image, we would
have

from Products.CMFDefault import Image, Document <--- you can add others I
suppose ie DiscussionItem, NewsItem, Link --->

.....
<<----- create the image , if you want to have an image, object follow the
how-to by Greg -->>
<<----- then to add additional objects at creation time, you would create an
entry for each one as follows, replacing Document.addDocument with method
you want to add ---->

        # 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)
                            )
        # give the image the correct portal type
        ob = f._getOb( 'index_html' )
        if hasattr(ob, '_setPortalTypeName'):
            ob._setPortalTypeName('Document')
        # Overcome an apparent catalog bug.
        f.index_html.reindexObject()


Remeber index_html is a document type, you just give it that name.

I am not sure what you are trying to achieve, you want at creation time for
the cmf to generate an index_html (presumably from a template?) an image and
an additional document??

So if this is the case, I suppose, you could add after your index_html
creation:

# Create MyNewDocument: open and read 'MyNewDocument.dtml' from
'Products/dtml'
        fileobj = open(os.path.join(product_path, 'dtml',
'MyNewDocument.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
                            , 'MyNewDocument'
                            , member_id+"'s NewDocument Template"
                            , member_id+"'s DocumentTemplate"
                            , "html"
                            , (filedata % member_id)
                            )
        # give the image the correct portal type
        ob = f._getOb( 'MyNewDocument' )
        if hasattr(ob, '_setPortalTypeName'):
            ob._setPortalTypeName('Document')
        # Overcome an apparent catalog bug.
        f.MyNewDocument.reindexObject()


If you want to add a default user to add properties to the rest of the
users, I think that is wrong, but I am not an expert;^)

In my situation I have added in the portal_memberdata property sheet
additional properties such as companyname, telephone etc, so if I want to
add any additional properties I would do it here. So once this is added, in
your join form you must give the option for your users to add this optional
information if they so wish.

So, the $64,000 question is how does this information gets automatically
added to the document template you just created??

I am affraid i have not reached ZEN enlighment, but would guess would use a
python script to populate this.

I hope this has been of help.

Norman

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


Greg,

	I have been trying to get this to work correctly.  I have been having
trouble getting it called.  I think I don't quite understand how to get a
method called in the afterAdd method. I thought I could just put some code
there and it would always run for me.  Evidently this is not the case.

	What I would really like to achieve with this is to have it run when ever a
user is created.  More so, it would go through a directory that is readily
available to an administrator who could add items to the list he would like
to see populate at creation.  This would include/exclude things like:

index_html
image
document

or any other valid object type.  Then he could then decide which items the
user could or could not modify.

Next I would also like to see in this directory a default user.  This user
object would be special in that you could modify this object and it would be
template for all users create afterwards.  The advantage here is that I
could add an attribute to all newly created users of the name email.  Then I
could populate that attribute when I create the user or have the user modify
it.  This would allow for me to have it go with the user.  Currently I don't
see how I would achieve this.  Ideas?

This is how I envision how it would work.  I'm trying to design it so that
anyone(admin level) could modify one directory and that would change all new
users.  This person would then know which objects to expect to be present.

Any suggestions welcomed.

Josh

-----Original Message-----
From: Grégoire Weber [mailto:gregoire.weber@switzerland.org]
Sent: Tuesday, August 21, 2001 2:07 AM
To: josh@pdxbands.com
Cc: zope-cmf@zope.org; Norman Khine
Subject: RE: [Zope-CMF] Re: How-To: Automatically Add Objects at CMF
Member Creation Time


Hi Josh,

I wasn't reading the list the last two (three?) weeks so I missed this ...
:-(

Thanks for mentioning that! Did you implement this in your Portal or
is it just a code snipped waiting to be inserted at the correct place?

I agree with you that something like this should be in the core. I made
this hotfix product because my implementation has only prototype state
(forthe moment) and I didn't want to invest too much time in a much
cleaner solution.

For the moment I do not have the resources to do the thing the right way,
so proposing a change to the CMFDefault code base.

Greg

At 20:37 20.08.01 -0700, you wrote:
> Greg/Norman,
>
> 	I have been following this and am interested in achieving the same
> solution.  Earlier I ask this same question a while back and received a
good
> solution from another user(Marc and Dan).  Below is the last email I
> received with some sample code.  I have yet to figure out the last part of
> this as I can not seem to understand how to get the Afteradd to call the
new
> script.  If that was achieved then all the objects in the directory would
> then automatically populate into the users home directory.  You could then
> make a template area and when you want to add a new default file for a
user
> you just have to add it to the directory and presto it is added when a
user
> is created.  It seems to me as an easier solution.
>
> 	Would either you or anyone else know how I call the script from
> registertool.afteradd?
>
> Thanks.  I would really like to see this added to the CMF core as it seems
> like a logical solution for many people.  I relate the creation of a user
> similar to the creation of a user on a system.  In unix you have a skel
dir
> that includes all the default files to be created when a new user is
added.
> Makes sense and makes the default user customizable very easily.
>
> Josh
>
> Code>>>>
>
>
>
> Message: 5
> Date: Thu, 02 Aug 2001 00:21:42 -0400
> Subject: Re: [Zope-CMF] how to modify the add user method?
> From: marc lindahl <marc@bowery.com>
> To: <zope-cmf@zope.org>
>
> I did this, and was going to put together a how-to, haven't had time yet.
> But basically, in register.dtml, called this script
> (createUserDefaults.pys), which I'll put below.  Modified registered.dtml
> also, so that I could print a result string from the function (optional
> geekiness).  Also, the .pys had to have a proxy role of owner in order to
> work.  Here's the pythonscript (the lines will probably be wrapped in the
> wrong place...):
>
> #copy stuff from user_defaults to user folder, build default mypic image
> #depends on folder user_defaults with everything there copied
> #and an image user_default_mypic both in the same folder as this script
> #
> uf = container.portal_membership.getHomeFolder(username)
>
> uf.manage_permission('Add Documents, Images, and Files', ['Anonymous',
> 'Member', 'Owner','Manager','Reviewer'], 1)
> uf.manage_permission('Add portal content', ['Anonymous', 'Member',
> 'Owner','Manager','Reviewer'], 1)
>
> obs =
>
container.user_defaults.manage_copyObjects(container.user_defaults.objectIds
> ())
> uf.manage_pasteObjects(obs)
>
> #uf.mypic.manage_setLocalRoles(username, ['Owner'])
>
> #change this one back, since we're operating in a known, limited situation
> uf.manage_permission('Add Documents, Images, and Files', [], 1)
> uf.manage_permission('Add portal content', [], 1)
>
> return 'Set up ' + `uf.getId()` +' with default content '+
> `container.user_defaults.objectIds()`

_____________________________________
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