Dynamic class from python script (?)
Dear Zopistas, i have an old zope application that present data from a database in such a manner <dtml-in "sql_methods.select_user()"> <dtml-var firstname><dtml-var lastname> </dtml-in> I had to change the methods that returned data from the database, and it is no longer possible to return data directly from zsql methods. Instead i read them in a script, perform some processing and return a dictionary with exactly the same mappings. I thought the application would work without any change but it seems this is not the case (variables in dtml-in can not be found, kinda makes sense now, the dictionary values are not properties...). So i created class that dynamically contain all data returned from my script. The class is something like this class foo: dct ={} def fill(self,temp_dct): self.dct = temp_dct def __getattr__(self,val): return self.dct[cal]
From pure python it works fine. Unfortunately i can not use it in a zope python script because of the __getattr__ method, so i put the class definition in an external method and use it in the python script (it returns an instance of the class). But dtml still returns me some strange errors. First, when the instance is created/accessed, some zope-like methods are called on it (for example getId, cant figure out why), and even if i implement them (dummy) it returns me authorization errors.
Any idea, or alternative solution would be more than helpful ;) My main objective is not to change the zope application Thank you.... PS sorry for the length of my mail, but it is kinda complicated problem :) -- Dimitris Koukis Software Engineer koukis@vtrip.net
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Dimitris Koukis wrote:
Dear Zopistas,
i have an old zope application that present data from a database in such a manner <dtml-in "sql_methods.select_user()"> <dtml-var firstname><dtml-var lastname> </dtml-in>
I had to change the methods that returned data from the database, and it is no longer possible to return data directly from zsql methods. Instead i read them in a script, perform some processing and return a dictionary with exactly the same mappings. I thought the application would work without any change but it seems this is not the case (variables in dtml-in can not be found, kinda makes sense now, the dictionary values are not properties...).
Try the 'mapping' parameter for 'dtml-in':: <dtml-in name="your_python_script" mapping> <dmtl-var name="firstname"><dtml-var name="lastname"> </dtml-in> Tres. - -- =================================================================== Tres Seaver +1 540-429-0999 tseaver@palladion.com Palladion Software "Excellence by Design" http://palladion.com -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2.2 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFF42Y8+gerLs4ltQ4RAiw3AKDLy3Sl4txFSc44BPQD/4DLKl1FTQCfWe7u EW84MPaI7lMzV5rOajsPtrI= =4fDO -----END PGP SIGNATURE-----
Tres, thank you very much for your quick reply. Indeed it works with the mapping parameter, but the application has a large number of files and i was hoping that i wouldn't have to change them all ;) On the other hand it is a simple change, i can do that with a script if there is no there solution. Thanx again for your help :) Tres Seaver wrote:
Dimitris Koukis wrote:
Dear Zopistas,
i have an old zope application that present data from a database in such a manner <dtml-in "sql_methods.select_user()"> <dtml-var firstname><dtml-var lastname> </dtml-in>
I had to change the methods that returned data from the database, and it is no longer possible to return data directly from zsql methods. Instead i read them in a script, perform some processing and return a dictionary with exactly the same mappings. I thought the application would work without any change but it seems this is not the case (variables in dtml-in can not be found, kinda makes sense now, the dictionary values are not properties...).
Try the 'mapping' parameter for 'dtml-in'::
<dtml-in name="your_python_script" mapping> <dmtl-var name="firstname"><dtml-var name="lastname"> </dtml-in>
Tres. -- =================================================================== Tres Seaver +1 540-429-0999 tseaver@palladion.com Palladion Software "Excellence by Design" http://palladion.com
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev ) -- Dimitris Koukis Software Engineer koukis@vtrip.net
participants (2)
-
Dimitris Koukis -
Tres Seaver