Thursday, May 29, 2008

Remember: overriding Fullname by computed field

I created a new member class using remember. I wanted to override the fullname field, computing the fullname for a member from their first name and surname.

I did this before for Plone 2.5 (hand-coded then, using ArgoUML now) and it was fairly easy: create a new member type based on remember, insert a computedfield "fullname" with accessor "Fullname" and that was that. On Plone 3.1.1 it was slightly harder.

First, I noticed i had to change "accessor=getFullname" instead of "accessor=Fullname", because if i didn't my new member wouldn't even get a join_form but an attribute error for getFullname.

Second, when i registered a member of my new member type i got an "AttributeError: setFullname". It turns out that this method is called in remember.content.member, in register:
self.setFullname(str(unicode_name))

(Funny thing is, i did this same thing on Plone 2.5 (remember 1.0b1, membrane 1.0, Archetypes 1.4.6 final) and it worked. The self.setFullname in remember was also present in this version.)

My solution was to add a dummy method setFullname(self, name) to the member class. ArchGenXML didn't create the parameters I specified in the UML, so i inserted them manually and they are preserved each generator run.