gotcha@swing.be writes:
Is there a place where pluggable brains mechanism is described ? I forgot where I saw a description.
But it is incredibly simple: You can wrap an arbitrary class instance around your database rows. This transforms your rows into full featured objects with the columns (among others) as attributes and the methods defined by the class as potential behaviour. What elso do you need to know? Dieter
I would like to understand how to do this in Zope also. I've done similar things in Delphi and C++. But am having a little trouble seeing how to do it in Zope. Below is a snippet from a document that was suggested however It's not clear how the data is "Wrapped" by the class. Can someone explain this. I would be will to document it if I can figure this out. ----------------- snippet ----------------------------------------- Brains allow you to associate a Python or ZClass with a Record object. Consider the example class: class Employee: def fullName(self): """ return the full name in the form 'John Doe' """ return self.first_name + ' ' + self.last_name def yearlyIncome(self): """ calculate the employees yearlyIncome """ return (self.weekly_hours * self.hourly_wage * 52) This class is then mixed in the with Record class which defines the behavior for Record objects. When a Record object with Brains is instanciated as the result of a SQL query, those objects will have Employee as a base class, giving the resultant Record objects behavior, as well as data: <dtml-var standard_html_header> <dl> <dtml-in Employees> <dt><dtml-var employee_id></dt> <dd><p><dtml-var fullName> makes an estimated <dtml-var yearlyIncome fmt=dollars> per year.</p> </dd> </dtml-in> </dl> <dtml-var standard_html_footer> -----Original Message----- From: zope-admin@zope.org [mailto:zope-admin@zope.org]On Behalf Of Dieter Maurer Sent: Thursday, September 14, 2000 1:40 PM To: gotcha@swing.be Cc: zope@zope.org Subject: Re: [Zope] Pluggable brains gotcha@swing.be writes:
Is there a place where pluggable brains mechanism is described ? I forgot where I saw a description.
But it is incredibly simple: You can wrap an arbitrary class instance around your database rows. This transforms your rows into full featured objects with the columns (among others) as attributes and the methods defined by the class as potential behaviour. What elso do you need to know? Dieter _______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
Stuart Foster writes:
Below is a snippet from a document that was suggested however It's not clear how the data is "Wrapped" by the class. Can someone explain this. I would be will to document it if I can figure this out. You wrap via the "Advanced Tab" of a Z SQL method.
Dieter
participants (2)
-
Dieter Maurer -
Stuart Foster