Created by ZopeOrgSite
. Last modified 2000-10-16 07:08:46.
Here's a step-by-step for creating a pluggable brain.
Create at .py module in your Extensions/ directory. For example
create the following OrderLine.py file.
class OrderLineClass:
"""A simple pluggable brain example for an order line."""
def subtotal(self):
return self.quantity * self.amount
Create an ZSQLMethod, named order_line_query, using the following SQL:
select item, quantity, amount from order_line
Click on the 'Advanced' tab for the ZSQLMethod, enter the name
of the module as 'OrderLine.py' and the name of the class as
'OrderLineClass'. Effectively, this class will become a mixin
class for the object returned from the ZSQLMethod.
Not only can you access each column of each row of the ZSQLMethod method
as an attribute of an instance of the order_line_query class -- as this
is the functionality of ZSQLMethods -- but, you can use the
methods defined in the associated python module.
Here is how this looks from DTML:
<dtml-in order_line_query>
Item: <dtml-var item>
Qty: <dtml-var quantity>
Amt: <dtml-var amount>
Sub: <dtml-var subtotal>
</dtml-in>
For more information on ZSQLMethods, see the ZSQLMethods documentation.
http://www.zope.org/Documentation/Guides/ZSQL/