Hello,

As I'm using betahaus.emaillogin[1] in my application I'm wanting to
override the generation of the username as this is a little confusing
for users as they expect to login with their email address but we're
still asking them to enter a username.

I've tried to override this as follows in my member schema:

    # Overriding the id field as we're using betahaus.emaillogin
    atapi.ComputedField('id',
                       expression = "context.setId()",

index=('membrane_tool/ZCTextIndex,lexicon_id=member_lexicon,index_type=Cosine 
Measure|TextIndex:brains',
                              'FieldIndex:brains'),
                 widget=atapi.ComputedWidget(label='User name'),
                 regfield=0,
                 user_property=True,
                 ),

and I've setup the setId method on the member content type as follows
(the getName method is an accessor for a StringField where users can
enter their fullname):

    def setId(self, id=''):
        "Overriding the username generator"
        import pdb;pdb.set_trace()
        if self.getName():
            if not getattr(self, 'subscribememberid', None):
                names = self.getName().split()
                if len(names) > 1:
                    firstname = names[0]
                    surname = names[-1]
                    id = firstname[:1]+surname
                else:
                    id = names[0]
                catalog = getToolByName(self.context, 'portal_catalog')
                existing = catalog(id=id, portal_type='Subscribemember')
                if len(existing) != 0:
                    try:
                        i = int(id[-1])
                        id = id+str(i+1)
                    except:
                        id = id+'1'
                    return self.setId(id)
                else:
                    setattr(self, 'subscribememberid', True)
            else:
                return getattr(self, 'subscribememberid')

As you can see I just grab the first initial of the firstname and the
surname and then check that no user exists for that username.

When I run my functional test, though, it doesn't create the user and
doesn't even enter the setId method (as you can see I've got a pdb in
there). Its supposed to return 'You have been registered as a member.'
but instead I get 'Changes saved.' as a status message.

Any tips on how I *should* be implementing this?

Thanks,
Tim



--
Archive: 
http://www.openplans.org/projects/remember/lists/remember/archive/2009/05/1243814877667
To unsubscribe send an email with subject "unsubscribe" to 
[email protected].  Please contact 
[email protected] for questions.

Reply via email to