Help with iterating thru a list of objects
Hello! I need to display the results of an sql query and I need to compare the value of field A in the current item with the value of field A in the previous item, in order to display things correctly. Doing this in a Python script seems overkill, since I only need to control the display of things. I have crancked upp a lot of info in the result of the query for optimization reasons so changing the query is out of the question. Any help is appreciated. Thank you, /dario - -------------------------------------------------------------------- Dario Lopez-Kästen Systems Developer Chalmers Univ. of Technology dario@ita.chalmers.se ICQ will yield no hits IT Systems & Services
Python Scripts are never overkill. The only disadvantage with replaceing DTML logic with small Python Scripts is that the list of objects in the ZMI become very long. In DTML: <dtml-call "REQUEST.set('prev_A','#notlikelytobe#')"> <dtml-in sql_query> <dtml-if "A == REQUEST['prev_A']"> Do something </dtml-if> <dtml-call "REQUEST.set('prev_A',A)"> </dtml-in> Or in the superior alternative (script): prev_A= "#notlikelytobe#" for rec in context.sql_query(): if rec.A == prev_A: Do something prev_A = rec.A ----- Original Message ----- From: "Dario Lopez-Kästen" <dario@ita.chalmers.se> To: <zope@zope.org> Sent: Friday, June 29, 2001 11:22 AM Subject: [Zope] Help with iterating thru a list of objects Hello! I need to display the results of an sql query and I need to compare the value of field A in the current item with the value of field A in the previous item, in order to display things correctly. Doing this in a Python script seems overkill, since I only need to control the display of things. I have crancked upp a lot of info in the result of the query for optimization reasons so changing the query is out of the question. Any help is appreciated. Thank you, /dario - -------------------------------------------------------------------- Dario Lopez-Kästen Systems Developer Chalmers Univ. of Technology dario@ita.chalmers.se ICQ will yield no hits IT Systems & Services _______________________________________________ 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 )
Dario Lopez-Kästen wrote:
Hello!
I need to display the results of an sql query and I need to compare the value of field A in the current item with the value of field A in the previous item, in order to display things correctly. <...>
Well, I don't know if it fits in your case, but did you think of dtml-ins marvellous grouping abilities? You just have to sort on an attribute and afterwards you can use first-<attribute> and last-<attribute> to determine, if the values of the attribute have changed: <dtml-in sql-search sort=office> <dtml-if first-office> <h1><dtml-var office></h1> <table> </dtml-if> <tr><th>Name</th><td>&dtml-name;</td></tr> <dtml-if last-office> </table> </dtml-if> </dtml-in> <dtml-unless there's no typo in it and you have defined all the variables>it may work</dtml-unless> ;-) happy zoping, Michael -- Michael Gutmann M.A. gutmann@uni-duesseldorf.de Multimediazentrum Heinrich-Heine-Universitaet Duesseldorf
Michael Gutmann wrote:
Dario Lopez-Kästen wrote:
Hello!
I need to display the results of an sql query and I need to compare the value of field A in the current item with the value of field A in the previous item, in order to display things correctly. <...>
Well, I don't know if it fits in your case, but did you think of dtml-ins marvellous grouping abilities? You just have to sort on an attribute and afterwards you can use first-<attribute> and last-<attribute> to determine, if the values of the attribute have changed:
<... snip example...> Thanks, but I don't think this is what I need; i believe first and last only apply to the current set in the dtml-in; I need to determine changes in the middle of the returned set several times. The solution that Peter Bengtsson suggested is the one I'll use; it is exactly the same that I use in the PL/SQL appliaktion that I am porting to Zope. I just wasn't sure that it was the best way of doing things. Thanks to both of you for your reply. For the curious living in sweden and working on student systems for Higher Education: What I am porting is an app that displays the personal, relevant information from LADOK for students that are logged in ("Studiemeritförteckning på WWW"). I wrote it in PL/SQL first, and now I am porting it to Zope to better integrate it with our Portal project. For details, mail me. I am not finished yet, but I've made good progress, considering that I am on vacation right now :-)) Sincerely, /dario
participants (3)
-
Dario Lopez-Kästen -
Michael Gutmann -
Peter Bengtsson