Uh, so "pluggable brains" _is_ the ability for Zope to return records as instances of a user-definable class? It may be a vivid term, but descriptive it ain't. :-) I have a related question. I need to post-process a query result set using Python; I simply want to (a) go through each record and add (or set) a column, and (b) reorder the records. Can you give me a simple example of how to do this? As far as I can see, records returned by SQL Methods are instances of a special class "r" which descends from Record, Acquisition.Implicit and an optional user-defined class (the "brain", I guess). It seems that when such an instance is created, each column is set as an attribute on the instance. If so, I guess I can simply put the records into a list, add my column as a vanilla Python attribute, and reorder them as I wish, and then return them for use in DTML? Correct? -- Alexander Staubo http://www.mop.no/~alex/ "Reality is that which, when you stop believing in it, doesn't go away." --Philip K. Dick
-----Original Message----- From: zope-admin@zope.org [mailto:zope-admin@zope.org]On Behalf Of Phillip J. Eby Sent: 5. juli 1999 02:20 To: Alexander Staubo; Zope Mailing List (E-mail) Subject: Re: [Zope] Pluggable brains?
At 01:07 AM 7/5/99 +0200, Alexander Staubo wrote:
Could somebody explain the concept of pluggable brains? I have come across this phrase more than once, and I still don't know what it is. Is there any documentation on this?
Is it by any chance related to an SQL Method's ability to represent data records with Python classes?
Yes. Sorry for the term, I picked it up from Jim Fulton back when it was an about-to-be-added feature for Principia/Aqueduct. As with so many Fultonisms, it's vivid and tends to stick in one's (non-pluggable) brain.
_______________________________________________ Zope maillist - Zope@zope.org http://www.zope.org/mailman/listinfo/zope
(For developer-specific issues, use the companion list, zope-dev@zope.org - http://www.zope.org/mailman/listinfo/zope-dev )
At 02:28 05/07/99 , Alexander Staubo wrote:
Uh, so "pluggable brains" _is_ the ability for Zope to return records as instances of a user-definable class?
It may be a vivid term, but descriptive it ain't. :-)
I have a related question. I need to post-process a query result set using Python; I simply want to (a) go through each record and add (or set) a column, and (b) reorder the records. Can you give me a simple example of how to do this? As far as I can see, records returned by SQL Methods are instances of a special class "r" which descends from Record, Acquisition.Implicit and an optional user-defined class (the "brain", I guess). It seems that when such an instance is created, each column is set as an attribute on the instance. If so, I guess I can simply put the records into a list, add my column as a vanilla Python attribute, and reorder them as I wish, and then return them for use in DTML? Correct?
Indeed, just create the 'Brain' (Igor, is that lightning storm here yet?), and have it set the attribute. The reordering is trickier. You could use the sort attribute of the #in tag. If the order cannot be derived from any existing attributes, you just add one to the brain object (Igor, tweezers please), that, if sorted on, will create the right order. Just put a module in the Extensions directory of your Zope installation, let call it MyBrains.py. In it you define your class: class SmartRecord: static_attr = 'A Static Attribute' def dyn_attr: return 'A Dynamic Attribute' And on the 'Advanced' tab of your Z SQL Method you specify this class and the file it is in ('SmartRecord' and 'MyBrains', or 'MyBrains.py'). From now on, you can refer to static_attr and dyn_attr as if they were columns of the result set. PS. Above code is untested, YMMV -- Martijn Pieters, Web Developer | Antraciet http://www.antraciet.nl | Tel: +31-35-7502100 Fax: +31-35-7502111 | mailto:mj@antraciet.nl http://www.antraciet.nl/~mj | PGP: http://wwwkeys.nl.pgp.net:11371/pks/lookup?op=get&search=0xA8A32149 ------------------------------------------
participants (2)
-
Alexander Staubo -
Martijn Pieters