Dynamic Reference, mixing ZOPE and SQL
I have a sequence of code that is monstrously inefficient and am looking for help. I am storing the id tag of an ExtFile object in my sql database along with other information and am now creating a page that displays info from the database record by record. For each record displayed, I also want to pull the file size from the Zope side of things. The method which works is something like this: <dtml-in my_query> <dtml-comment> query returns file_id amongst other values </dtml-comment> <dtml-with files> <dtml-in "objectValues(['ExtFile'])"> <dtml-if "id == file_id"> <dtml-var size> </dtml-if> </dtml-in> </dtml-with> </dtml-in> With a 1000+ ExtFile objects in the "files" folder, the search is ok for just one record being displayed; however, if this page is displaying all 1000+ files based on the SQL records, then for each SQL record returned it is iterating through the entire contents of my files folder, and is very slow to resolve. What I am looking for is a way to say: <dtml-in my_query> <dtml-comment> query returns file_id amongst other values </dtml-comment> <dtml-var files.file_id.size> //where file_id is a dynamic ref // not the id itself </dtml-in> However, I don't know a good method for doing a dynamic reference here, such as the following which fails: <dtml-in my_query> <dtml-comment> query returns file_id amongst other values </dtml-comment> <dtml-with files> <dtml-in "objectValues(['ExtFile'])._['file_id']"> <dtml-var size> </dtml-in> </dtml-with> </dtml-in> I am just extrapolating from things like using "sequence-item" in an expression changes it over to "_['sequence-item']". Not even sure the dtml-in would work the way I want, but the idea is there. Maybe to effectively use something like this to reference an object I explicitly know: <dtml-in my_query> <dtml-comment> query returns file_id amongst other values </dtml-comment> <dtml-var "files._['file_id'].size"> </dtml-in> The above approach throws unauthorized exceptions, so obviously not the right way to go about it. Anyone know the correct syntax for achieving this both inside a python expression and/or as a direct dtml expression? Thanks, -- Ryan T. Bard Webmaster/Software Developer Department of Medical Education University of Miami School of Medicine Office: (305) 243-3273 The information contained in this transmission may contain privileged and confidential information, including patient information protected by federal and state privacy laws. It is intended only for the use of the person(s) named above. If you are not the intended recipient, you are hereby notified that any review, dissemination, distribution or duplication of this communication is strictly prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message.
Ryan T. Bard wrote at 2004-1-30 13:17 -0500:
I have a sequence of code that is monstrously inefficient and am looking for help. I am storing the id tag of an ExtFile object in my sql database along with other information and am now creating a page that displays info from the database record by record. For each record displayed, I also want to pull the file size from the Zope side of things.
The method which works is something like this:
<dtml-in my_query> <dtml-comment> query returns file_id amongst other values </dtml-comment>
<dtml-with files> <dtml-in "objectValues(['ExtFile'])"> <dtml-if "id == file_id"> <dtml-var size> </dtml-if> </dtml-in> </dtml-with>
Replace this with <dtml-with expr="_.getattr(files,file_id)"> <dtml-var size> </dtml-with> -- Dieter
participants (2)
-
Dieter Maurer -
Ryan T. Bard