[Zope] Returning database results similar to google search

J. Cameron Cooper jccooper at jcameroncooper.com
Fri Dec 5 22:48:00 EST 2003


Lyz at PrincessLeia.com wrote:

>On Fri, Dec 05, 2003 at 01:08:01PM -0800, Dylan Reinhardt wrote:
>  
>
>>Here's an untested, top-of-head Python Script that assumes you pass in a
>>variable called offset that defaults to 0.
>>
>>----
>>records = context.your_zsql_method(args)
>>batch_size = 5
>>
>>last_record = min([offset+batch_size,len(records)])
>>
>>for record_num in range(offset, last_record):
>>    print records[record_num]['some_info']
>>
>>for page in range(0,len(results),batch_size):
>>    print '<a href=your_url?offset=%s>%s</a>' % (page,page/batch_size)
>>return printed
>>-----
>>
>>It's incomplete and ugly, but should get you well on your way.
>>    
>>
>This is exactly what I needed to get me on my way. Thanks so much!
>
See also

http://zope.org/Members/peterbe/DTML2ZPT/#example4
http://www.zopelabs.com/cookbook/1015785843
http://www.zopelabs.com/cookbook/1019946889
and ZTUtils.Batch in 
http://www.zope.org/Documentation/Books/ZopeBook/2_6Edition/AppendixB.stx

          --jcc

-- 
"My point and period will be throughly wrought,
Or well or ill, as this day's battle's fought."





More information about the Zope mailing list