Oleksandr Moskalenko schrieb:
> * Diez B. Roggisch <[EMAIL PROTECTED]> [2008-11-03 21:03:15 +0100]:
> 
>> Oleksandr Moskalenko schrieb:
>>> I'm stuck on tg2 1.9.7b1 tg.decorators.paginate. I keep getting a NameError:
>>> name 'collection' is not defined when trying to set up a @paginate decorator
>>> where collection is the name of my DBSession.Query object. Also, the
>>> docstrings for the decorator just mention to use
>>> ${c.paginators.<name>.pager()} to render pages, so it would be immensely
>>> helpful if there was more information or example controller/template code to
>>> show new people how to use it properly.
>> Can you provide some code?
>>
>> Diez
> 
> Here is my currently working controller/template pair without pagination with
> all data in one big table with sortable columns:
> 
> Controller:
> 
>     @expose('chemcupboard.templates.listall')
>     def listall(self, sort="id"):
>         invquery = DBSession.query(t_inventory).order_by(sort)
>         return dict(title='CCM - Chemical Inventory', organization = 'John 
> Doe Lab', iquery = invquery, sort = None)
> Template:
> 
>         <table>
>             <tr class="heading">
>                 ${h.th_sortable(sort, "id", "ID", "?sort=id")}
>                 ${h.th_sortable(sort, "name", "Chemical Name", "?sort=name")}
>                 ${h.th_sortable(sort, "location", "General Location", 
> "?sort=location")}
>                 ${h.th_sortable(sort, "sub_location", "Sub Location", 
> "?sort=sub_location")}
>             </tr>
>             <tr py:for="ilist in iquery">
>                 <td>${ilist.id}</td>
>                 <td>${ilist.name}</td>
>                 <td>${ilist.location}</td>
>                 <td>${ilist.sub_location}</td>
>             </tr>
>         </table>
> 
> Attempt to add pagination:
> 
> Controller:
> 
>     @expose('chemcupboard.templates.list')
>     @paginate('invquery', items_per_page=30, use_prefix=False)
>     def list(self, sort="id"):
>         invquery = DBSession.query(t_inventory).order_by(sort)
>         return dict(title='CCM - Chemical Inventory', organization = 'John 
> Doe Lab', iquery = invquery, sort = None)
> 
> Template:
> 
>     <div id="pagearea">
>         <p>
>         ${c.paginators.iquery.pager()}

**invquery** or **iquery**?

You need to spell things proper of course.

Diez

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears Trunk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/turbogears-trunk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to