[Product-Developers] Add Collection (ATTopic) on User Registration?

Brayton Osgood braytonosgood at gmail.com
Thu Jul 24 19:15:46 UTC 2008


I ended up using:

container= context
container.invokeFactory(type_name='Topic',id=id)
mytopic = context[id]

and then configuring from there.

The following tutorials/examples ended up being very helpful:

http://plone.org/documentation/how-to/add-content-programmatically
http://dev.plone.org/collective/browser/PressRoom/tags/3.1/content/PressRoom.py

Thanks Jon and JeanMichel for the help!
Brayton

On Jul 24, 2008, at 7:34 AM, JeanMichel FRANCOIS wrote:

> Hi Brayton,
>
> createObject return the id of the object created or raise an  
> exception.
> You need to traverse to it:
> mytopic = context.restrictedTraverse(id) or sth like this (get,
> unrestricted, ....)
>
> You also can use event handler or there is a PythonScript called to  
> create
> content on registration time, i can't remember the name of this one;
>
> JeanMichel FRANCOIS aka ToutPT
> Le Thursday 24 July 2008 02:13:26 Brayton Osgood, vous avez écrit :
>> Hi,
>>
>> I'm trying to automatically create Collections for each user that I
>> register. I haven't quite been able to figure out how to do this.
>>
>> If I add the following code to the end of my register.cpy:
>>> context.portal_factory.createObject(id='collection_for_'+username,
>>
>> type_name='Topic')
>>
>> it takes me to the TTW Collection creation page, but this isn't  
>> really
>> what I want.
>>
>> Alternatively I've tried calling another script from register.cpy
>>
>> where I have the following:
>>> ##Python Script (addCollection)
>>> ##parameters=user=None
>>>
>>> pf = context.portal_factory
>>>
>>> member = pm.getMemberById(user)
>>> id='collection_for_'+member
>>>
>>> mytopic = pf.createObject(id=id,type_name='Topic')
>>> mytopic.addIndex(friendlyName='Collection for '+fullname,
>>
>> description='Automatically refreshing folder with all content tagged
>> for '+fullname, enabled='True', criteria='user')
>>
>>> pf.doCreate(mytopic,id)
>>
>> return mytopic
>>
>>
>> This gives me the following error:
>> Exception Type  	AttributeError
>> Exception Value 	'str' object has no attribute 'addIndex'
>>
>> which implies that mytopic was created as a string, not a collection.
>> Any ideas on how I might fix this, or if it's even possible to do  
>> what
>> I'm trying?
>>
>> Thanks very much,
>> Brayton
>>
>> _______________________________________________
>> Product-Developers mailing list
>> Product-Developers at lists.plone.org
>> http://lists.plone.org/mailman/listinfo/product-developers
>
>
>
> _______________________________________________
> Product-Developers mailing list
> Product-Developers at lists.plone.org
> http://lists.plone.org/mailman/listinfo/product-developers





More information about the Product-Developers mailing list