paginate decorator not working for me

3 views
Skip to first unread message

jiri....@gmail.com

unread,
Jul 14, 2006, 3:09:39 AM7/14/06
to TurboGears
Hi to all,
according to ticket #1013
(http://trac.turbogears.org/turbogears/ticket/1013") I still can not
get paginate decorator working without patch.

I asked in IRC channel, but no one is using paginate decorator... :/
It is very handy an I can not belive that no one is using it (and it
works).

Is there another way to do pagination using TG? Will the paginate
decorator be supported in future?

Thanx
Jiri

Here is a patch again:

Index: turbogears/paginate.py
===================================================================
--- turbogears/paginate.py (revision 1629)
+++ turbogears/paginate.py (working copy)
@@ -14,10 +14,11 @@
allow_limit_override=False, max_pages=5):
def entangle(func):
def decorated(func, *args, **kw):
- page = int(kw.pop('tg_paginate_no', 1))
- limit_ = int(kw.pop('tg_paginate_limit', limit))
- order = kw.pop('tg_paginate_order', default_order)
- reversed = kw.pop('tg_paginate_reversed', None)
+ crp = cherrypy.request.params
+ page = int(crp.pop('tg_paginate_no', 1))
+ limit_ = int(crp.pop('tg_paginate_limit', limit))
+ order = crp.pop('tg_paginate_order', default_order)
+ reversed = crp.pop('tg_paginate_reversed', None)

if not allow_limit_override:
limit_ = limit

Nicky Ayoub

unread,
Jul 14, 2006, 10:43:24 AM7/14/06
to turbo...@googlegroups.com

I just started using it this week. It works great once you apply the patch. If we are
voting for future support here's my

  +1

Nicky


Hi to all,
according to ticket #1013

get paginate decorator working without patch.

I asked in IRC channel, but no one is using paginate decorator... :/
It is very handy an I can not belive that no one is using it (and it
works).

Is there another way to do pagination using TG? Will the paginate
decorator be supported in future?

Thanx
Jiri

Here is a patch again:

Index: turbogears/paginate.py
===================================================================
--- turbogears/paginate.py      (revision 1629)
+++ turbogears/paginate.py      (working copy)
@@ -14,10 +14,11 @@
             allow_limit_override=False, max_pages=5):
     def entangle(func):
         def decorated(func, *args, **kw):
-            page = int(kw.pop('tg_paginate_no', 1))
-            limit_ = int(kw.pop('tg_paginate_limit', limit))
-            order = kw.pop('tg_paginate_order', default_order)
-            reversed = kw.pop ('tg_paginate_reversed', None)

Tim Van Steenburgh

unread,
Jul 14, 2006, 3:47:02 PM7/14/06
to turbo...@googlegroups.com
Try adding **kw to the arg list of the function you're decorating.


Hi to all,
according to ticket #1013

get paginate decorator working without patch.

I asked in IRC channel, but no one is using paginate decorator... :/
It is very handy an I can not belive that no one is using it (and it
works).

Is there another way to do pagination using TG? Will the paginate
decorator be supported in future?

Thanx
Jiri

Here is a patch again:

Index: turbogears/paginate.py
===================================================================
--- turbogears/paginate.py      (revision 1629)
+++ turbogears/paginate.py      (working copy)
@@ -14,10 +14,11 @@
             allow_limit_override=False, max_pages=5):
     def entangle(func):
         def decorated(func, *args, **kw):
-            page = int(kw.pop('tg_paginate_no', 1))
-            limit_ = int(kw.pop('tg_paginate_limit', limit))
-            order = kw.pop('tg_paginate_order', default_order)
-            reversed = kw.pop ('tg_paginate_reversed', None)

Randall

unread,
Jul 15, 2006, 2:57:43 AM7/15/06
to TurboGears
I started using it today on trunk and it works well except for sorting.
The fields become links, but clicking the links does not sort the
fields.

Example URL when I click on the 'f3' field link:

http://localhost:8080/?tg_paginate_limit=10&tg_paginate_no=1&tg_paginate_reversed=True&tg_paginate_order=f3

And again:

http://localhost:8080/?tg_paginate_limit=10&tg_paginate_no=1&tg_paginate_order=f3

Here is the controller bit:

@expose(template="tgstark.templates.index")
@paginate('data', default_order='f1')
def index(self, **kwarg):
import time
data = []
for i in range(100):
data.append(dict(f1=str(i), f2=str(i), f3=str(100 - i)))
return dict(grid=data_grid, data=data)

And the widget bit:

from turbogears.widgets.datagrid import PaginateDataGrid from
turbogears.widgets.datagrid import DataGrid

def createDataGrid():
Column = DataGrid.Column
def get(fieldname):
return lambda x: x.get(fieldname)
options = {'sortable':True}
fields = [
Column(name='f1', getter=get('f1'), title='f1',
options=options),
Column(name='f2', getter=get('f2'), title='f2',
options=options),
Column(name='f3', getter=get('f3'), title='f3',
options=options)
]
grid = PaginateDataGrid(fields=fields)
return grid

data_grid = createDataGrid()

Any idea what I'm doing wrong?

Tim Van Steenburgh

unread,
Jul 16, 2006, 9:58:32 PM7/16/06
to turbo...@googlegroups.com
You're not doing anything wrong.  The sorting only works if you're using SQLObject SelectResults.  It doesn't work for regular lists like you're using.  I have written a patch for this but I haven't had time to submit it yet.  Let me know if you need/want it right away and I'll email it to you.  Otherwise, I'll make a ticket for it as soon as I can.

Randall

unread,
Jul 21, 2006, 11:08:42 PM7/21/06
to TurboGears
I see that you can get at paginate from within a template, but how do I
get at the values from within the decorated controller method?

Jorge Godoy

unread,
Jul 22, 2006, 7:02:59 AM7/22/06
to turbo...@googlegroups.com
"Randall" <ran...@tnr.cc> writes:

> I see that you can get at paginate from within a template, but how do I
> get at the values from within the decorated controller method?

Old messages from this thread have already expired here... Can you explain a
bit better? If it is any value passed to your controller then it should be
available in one of your parameters to the function that is handling the
action. In my case here it is usually a dictionary "kwords".

--
Jorge Godoy <jgo...@gmail.com>

Randall

unread,
Jul 27, 2006, 4:51:42 PM7/27/06
to TurboGears
Sorry I wasn't clear. I meant how do I get at the paginate specific
values like what page is being requested, etc, because they're filtered
out of controller method's arguments. I found cherrypy.request.params,
so I'm OK. Thanks.

Randall

Randall

unread,
Jul 27, 2006, 4:58:22 PM7/27/06
to TurboGears
Now I'm having some new problems with it. I think this is a typical
scenario. I have a search form that posts to a method searchResults.
searchResults displays the paged results. I'm getting FormEncode
errors when trying to go to different pages.

The method is heavily decorated and includes valdation:

@expose(template="tgwater.planreview.templates.search_results")
@validate(form=createSearchForm)
@error_handler(search)
@paginate('projects', default_order='id')
def searchResults(self, **data):
#stuff

My validation is a FormEncode Schema defined for the form.

All works on the same post, but when following a link to a new page, I
get errors like this:

File
"/usr/lib/python2.4/site-packages/FormEncode-0.5.1-py2.4.egg/formencode/schema.py",
line 116, in _to_python
for name, value in value_dict.items():
AttributeError: 'unicode' object has no attribute 'items'

Seems like the arguments passed in the URL are not being marshalled.

Randall

unread,
Jul 27, 2006, 5:31:32 PM7/27/06
to TurboGears
The problem seems to be with compound widgets. Specifically, I'm using
an AutoCompleteField widget. If I remove it from the form, paging
works fine.

Randall

Jorge Godoy

unread,
Jul 27, 2006, 6:22:51 PM7/27/06
to turbo...@googlegroups.com
"Randall" <ran...@tnr.cc> writes:

I have AutoCompleteFields and I show them with paged datagrids. I can change
the page and keep the other part of the page intact. Maybe if you post some
code to the list or open a ticket with a quickstarted project that reproduces
your problem we could see it better...

--
Jorge Godoy <jgo...@gmail.com>

Randall

unread,
Jul 28, 2006, 1:48:08 PM7/28/06
to TurboGears
I did create a simple quickstarted app and it fails in the same way.
Are you using @validate(form=your_form)? That's what's tripping mine
up. I'm going to post a ticket with the quickstarted app attached.

Randall

unread,
Jul 28, 2006, 2:07:00 PM7/28/06
to TurboGears
ticket 1044

Nicky Ayoub

unread,
Jul 28, 2006, 3:39:43 PM7/28/06
to turbo...@googlegroups.com
We are also having this problem. To me it seems like the paginate urls are being constructed in such a way that the form variables are included as simple strings. Once the postback is called our validator complains because the values are now json-like strings. My guess is that since they where not marshalled through the submit process of the form, the to_python() magic never happend.

Jorge, would it be possible for you to show how you were able to solve the problem?

Thanks,

--
--
Nicky Ayoub
G-Mail Account

Randall

unread,
Aug 2, 2006, 4:12:26 PM8/2/06
to TurboGears
Nicky, have you made any progress?

Randall

> ------=_Part_273320_8853449.1154115583443
> Content-Type: text/html; charset=ISO-8859-1
> X-Google-AttachSize: 1620
>
> <br><br><div><span class="gmail_quote">On 7/27/06, <b class="gmail_sendername">Jorge Godoy</b> &lt;<a href="mailto:jgo...@gmail.com">jgo...@gmail.com</a>&gt; wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
> <br>&quot;Randall&quot; &lt;<a href="mailto:ran...@tnr.cc">ran...@tnr.cc</a>&gt; writes:<br><br>&gt; The problem seems to be with compound widgets.&nbsp;&nbsp;Specifically, I'm using<br>&gt; an AutoCompleteField widget.&nbsp;&nbsp;If I remove it from the form, paging
> <br>&gt; works fine.<br><br>I have AutoCompleteFields and I show them with paged datagrids.&nbsp;&nbsp;I can change<br>the page and keep the other part of the page intact.&nbsp;&nbsp;Maybe if you post some<br>code to the list or open a ticket with a quickstarted project that reproduces
> <br>your problem we could see it better...<br><br>--<br>Jorge Godoy&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;<a href="mailto:jgo...@gmail.com">jgo...@gmail.com</a>&gt;<br><br><br><br></blockquote></div><br>We are also having this problem. To me it seems like the paginate urls are being constructed in such a way that the form variables are included as simple strings. Once the postback is called our validator complains because the values are now json-like strings. My guess is that since they where not marshalled through the submit process of the form, the to_python() magic never happend.
> <br><br>Jorge, would it be possible for you to show how you were able to solve the problem? <br><br>Thanks,<br clear="all"><br>-- <br>--<br>Nicky Ayoub<br>G-Mail Account
>
> ------=_Part_273320_8853449.1154115583443--

Nicky Ayoub

unread,
Aug 2, 2006, 5:07:31 PM8/2/06
to turbo...@googlegroups.com
Not really. Mixing forms and paginate in the same method is still a problem.

What I have been doing is taking action at the controller method, and toss the Validator.
Since the kw dictionary holds JSON parsable strings, I use simplejson.loads() to get the data out.
Yeah I know it's sloppy...

I have not looked into paginate.py or the submit mechanisms of Turbogears in order to
find the root cause.

I'm working on a different part of the application now. Perhaps Mansi will be able to
have a look. It is still on our list of problems to solve.

Nicky
Reply all
Reply to author
Forward
0 new messages