[Zope] Zope Product and database help: ver. 2.5.1
Dieter Maurer
dieter@handshake.de
Wed, 8 Jan 2003 21:05:07 +0100
sameer chaudhry wrote at 2003-1-6 16:02 -0500:
> Two issues:
> 1)
>
> I have a product that I wrote in zope which is just a big hash. It
> loads in company names as keys, and from a text file, adds ticker
> items as each value for a particular key. Now I only want this huge
> dictionary to load once, which is when zope starts up (possibly in a
> global space), as I need one copy of it and I need that one copy to
> update every x number of minutes. Currently, I think, each user that
> views this product, loads his own copy of the hash, which makes it
> slow and a memory hog. I only want a single copy available to all
> users, and the data refresh time to be determined by the system or the
> user.
Put it into a Python module and provide accessors for the data.
The accessor functions will refresh as necessary.
Be careful about synchronization. You might be interested in
my product "SharedResource" (<http://www.dieter.handshake.de/pyprojects/zope>).
When you want to make it available to Python Scripts or Page Templates,
you need to provide security declarations allowing this.
Read the "Readme" in the "PythonScripts" product.
> 2)
>
> In the same python product, I am trying to access an ODBC database connection. I have tried 2 ways of accessing it, and both have failed. First I created a Z SQL method in the same directory as the Product, and tried to access that Z SQL method. My product subclasses SimpleItem, and so I tried self.getattr(name_of_Z_SQL_meth)(). The Z SQL method doesn't take any arguments, so that should have worked. Then I tried import SQL from Zope: from Products.ZSQLMethods.SQL import SQL, and running the SQL method directly. It always complains about the formation of the connection ID which I cannot seem to get right. Help on either of these issues would be greatly appreciated.
"getattr" is not a method but a function. It is used like
attr= getattr(obj,attrName)
Dieter