adding a custom attribute to a mybrain object
Hi, I'd like to sort of add some metadata to a returned mybrain before it gets handed to the skin for display. I've been thinking that it could be possible to just do a 'setattr' on my mybrain ... but it's not working since the brain is a very special object relatively to it's attributes (from what I understand browsing the code). It there a way to do that properly ? Thanks in advance, -- huron
Huron wrote:
I'd like to sort of add some metadata to a returned mybrain before it gets handed to the skin for display. I've been thinking that it could be possible to just do a 'setattr' on my mybrain ... but it's not working since the brain is a very special object relatively to it's attributes (from what I understand browsing the code). It there a way to do that properly ?
Brains are based on Record, a class dating back to the origins of zope. Records are quite... peculiar, let's say. They only allow setting attributes which are in their class's __record_schema__. Go figure. If I had your problem, I'd copy all the brain attributes on an instance of another trivial class deriving from object. brain.__record_schema__ will come in handy there. Florent -- Florent Guillaume, Nuxeo (Paris, France) Director of R&D +33 1 40 33 71 59 http://nuxeo.com fg@nuxeo.com
Hi Florent, and thanks for your reply ... debugging those brains objects, I've seen that there is (so to say) a double indirection to store attributes, involving this __record_schema__ you're talking about :
myBrain.__record_schema__['mynewatttribute']=35 myBrain[35]='my_new_value' myBrain.mynewatttribute 'my_new_value'
This seems to work, as long as the new attribute name does not collide with a metadata name or with an existing metadata index (35 in my example) ... -- huron
participants (2)
-
Florent Guillaume -
Huron