formatting the results of Zsql methods
I can iterate over the result set from a Zsql method and have each result display across the page and wrap at the page border or I can have them display down the page. I can't work out how to have say five across the page and then have multiple rows each with five results. Could anyone point me in the right direction? regards garry
Hi, Am Sa, den 25.09.2004 schrieb garry saddington um 21:42:
I can iterate over the result set from a Zsql method and have each result display across the page and wrap at the page border or I can have them display down the page. I can't work out how to have say five across the page and then have multiple rows each with five results. Could anyone point me in the right direction? regards
For example like this: chunksize=5 all=context.YourZSQLMethod().dictionaries() return [all[i:i+chunksize] for i in range(0,len(all),chunksize)] this will return a list of lists with 5 elements each. (the last list could be 1...5 elements) You could use <table> <tr tal:repeat="rows here/the_python_script_above"> <td tal:repeat="col rows" tal:content="col">somevalue</td> </tr> </table>
garry saddington wrote:
I can iterate over the result set from a Zsql method and have each result display across the page and wrap at the page border or I can have them display down the page. I can't work out how to have say five across the page and then have multiple rows each with five results. Could anyone point me in the right direction?
A PythonScript is your friend, here. ##Script (Python) "inRows" ##title=Chunk a list into equal-length sub-lists ##parameters=source, chunk_size=5 # result = [] for start in range(0, len(source), chunk_size): result.append(source[start:start+chunk_size]) return result Tres. -- =============================================================== Tres Seaver tseaver@zope.com Zope Corporation "Zope Dealers" http://www.zope.com
A PythonScript is your friend, here.
##Script (Python) "inRows" ##title=Chunk a list into equal-length sub-lists ##parameters=source, chunk_size=5 # result = [] for start in range(0, len(source), chunk_size): result.append(source[start:start+chunk_size]) return result
Tres. Thanks, this works but then I would have to slice up the dictionaries to get at the individual values, so I have come up with this. Can anyone see a problem with it or could I do it more simply?
<dtml-in getclasses> <dtml-if expr="_['sequence-number'] < 7"> <input type="checkbox" name="allocation.classid:records" value="<dtml-var classid>"> <dtml-var year><dtml-var teachgroup><dtml-var abbreviation> <dtml-elif expr="_['sequence-number'] ==7"> <input type="checkbox" name="allocation.classid:records" value="<dtml-var classid>"> <dtml-var year><dtml-var teachgroup><dtml-var abbreviation><br><br> <dtml-elif expr="_['sequence-number'] in range(8,14)"> <input type="checkbox" name="allocation.classid:records" value="<dtml-var classid>"> <dtml-var year><dtml-var teachgroup><dtml-var abbreviation> <dtml-elif expr="_['sequence-number'] ==15"> <input type="checkbox" name="allocation.classid:records" value="<dtml-var classid>"> <dtml-var year><dtml-var teachgroup><dtml-var abbreviation><br><br> <dtml-elif expr="_['sequence-number'] in range(16,22)"> <input type="checkbox" name="allocation.classid:records" value="<dtml-var classid>"> <dtml-var year><dtml-var teachgroup><dtml-var abbreviation> <dtml-elif expr="_['sequence-number'] ==23"> <input type="checkbox" name="allocation.classid:records" value="<dtml-var classid>"> <dtml-var year><dtml-var teachgroup><dtml-var abbreviation><br><br> <dtml-elif expr="_['sequence-number'] in range(24,30)"> <input type="checkbox" name="allocation.classid:records" value="<dtml-var classid>"> <dtml-var year><dtml-var teachgroup><dtml-var abbreviation> <dtml-elif expr="_['sequence-number'] ==31"> <input type="checkbox" name="allocation.classid:records" value="<dtml-var classid>"> <dtml-var year><dtml-var teachgroup><dtml-var abbreviation><br> </dtml-if> </dtml-in> regards garry
Hi, Am So, den 26.09.2004 schrieb garry saddington um 20:13:
A PythonScript is your friend, here.
##Script (Python) "inRows" ##title=Chunk a list into equal-length sub-lists ##parameters=source, chunk_size=5 # result = [] for start in range(0, len(source), chunk_size): result.append(source[start:start+chunk_size]) return result
Tres. Thanks, this works but then I would have to slice up the dictionaries to get at the individual values, so I have come up with this. Can anyone see a problem with it or could I do it more simply?
<dtml-in getclasses> <dtml-if expr="_['sequence-number'] < 7"> <input type="checkbox" name="allocation.classid:records" value="<dtml-var classid>"> <dtml-var year><dtml-var teachgroup><dtml-var abbreviation> ... <dtml-elif expr="_['sequence-number'] ==31"> <input type="checkbox" name="allocation.classid:records" value="<dtml-var classid>"> <dtml-var year><dtml-var teachgroup><dtml-var abbreviation><br> </dtml-if> </dtml-in>
Hm. For me it looks much like a problem with your eyes ;) Whats wrong with both the solutions we gave? Why do you do it wrong with lots of dtml when there are 2 examples that show it can be done within 3..4 lines? IF you _really_ want DTML here, you have <dtml-in methodcall><tr><dtml-in sequence-item mapping><td><dtml-var whateverthenameofthecolumnis></td></dtml-in></tr></dtml-in>
On Monday 27 September 2004 07:55, Tino Wildenhain wrote:
<dtml-in methodcall><tr><dtml-in sequence-item mapping><td><dtml-var whateverthenameofthecolumnis></td></dtml-in></tr></dtml-in>
Thanks for your help, I have now accomplished what I wanted with very few lines of code. The problem is that I had no experience of using dictionaries and the only mention of mapping objects is the appendix of the zope book with no examples as to how to use them. Your help has therefore been invaluable, my eyes are now wide open;) kind regards garry Final code: <table border> <dtml-in inrows> <tr><dtml-in sequence-item mapping><td> <input type="checkbox" name="allocation.classid:records" value="<dtml-var classid>"> <dtml-var year><dtml-var teachgroup><dtml-var abbreviation></td> </dtml-in></tr></dtml-in> </table>
participants (3)
-
garry saddington -
Tino Wildenhain -
Tres Seaver