[Zope-CMF] Batch member creation
Ausum Studio
ausum_studio@hotmail.com
Fri, 23 Aug 2002 02:14:26 -0500
(I'm sorry that the previous message had arrived after I found the solution,
possible due to a mail's delay .)
After extracting the data from the tab separated file - the first part of
Tres' script - I had this set of properties, by each future member: userid,
password, firstname, lastname and email. As I had to dig hard just to
realize that what I was looking for was right in front of my nose, I post
the external method that worked for me, hoping to help to save other
people's time. :)
def createmember(self):
from Products.CMFCore.utils import getToolByName
rt = getToolByName( self, 'portal_registration' )
rt.addMember( userid, password
, properties={ 'lastname' : lastname
, 'username' : userid
, 'email' : email
, 'firstname' : firstname
} )
...where 'lastname' and 'firstname' are property fields previously created
at portal_memberdata/Properties. The key thing is that you must repeat the
userid string within the dictionary, under the 'username' property name,
just to avoid time-wasting error messages. (You don't need to comment
out all those lines from RegistrationTool.py). The platform: Zope 2.5.1
and CMF 1.3
Ausum
p.s. Tres's script:
http://lists.zope.org/pipermail/zope-cmf/2002-April/012489.html
----- Original Message -----
From: "Ausum Studio" <ausum_studio@hotmail.com>
To: <zope-cmf@zope.org>
Sent: Wednesday, August 21, 2002 6:02 PM
Subject: [Zope-CMF] Batch member creation
> After digging into the external method that Tres posted a time ago, I came
> to try this method (external):
>
> def createmember(self):
> from Products.CMFCore.utils import getToolByName
> rt = getToolByName( self, 'portal_registration' )
> rt.addMember( 'testuser', 'demopass'
> , properties={ 'lastname' : 'Last Name'
> , 'email' : 'asd@asd.com'
> , 'firstname' : 'First Name'
> } )
> return "done"
>
> Provided 'lastname' and 'firstname' were previosuly created at
> portal_memberdata this should have worked, except for what I've found it'd
> be a bug within the default RegistrationTool.py. I didn't have time to
> analize what happens, so commenting out the lines below did the job, at
> least while performing the batch. Starting from line 100:
>
> def testPropertiesValidity(self, props, member=None):
>
> """ Verify that the properties supplied satisfy portal's
> requirements.
>
> o If the properties are valid, return None.
> o If not, return a string explaining why.
> """
> print props
> ## if member is None: # New member.
> ## username = props.get('username', '')
> ## if not username:
> ## return 'You must enter a valid name.'
> ## if not self.isMemberIdAllowed(username):
> ## raise ('The login name you selected is already '
> ## 'in use or is not valid. Please choose another.')
> ##
> ## if not props.get('email'):
> ## return 'You must enter a valid email address.'
> ##
> ## else: # Existing member.
> ## # Not allowed to clear an existing non-empty email.
> ## if (member.getProperty('email') and
> ## not props.get('email', 'NoPropIsOk')):
> ## return 'You must enter a valid email address.'
> return None
>
> Can someone point out what's wrong with it?
>
> Thanks,
>
>
>
> Ausum
>
> _______________________________________________
> Zope-CMF maillist - Zope-CMF@zope.org
> http://lists.zope.org/mailman/listinfo/zope-cmf
>
> See http://collector.zope.org/CMF for bug reports and feature requests
>