aspineux a écrit :
> I thing you can also get the paginate parameters from the original
> http request stored by cherrypy.
> I thing this is called
>
> cherrypy.request.params
>
> look the cherrypy doc  to be sure.
>
> Then extract the paginate parameters and do something like
>
> for i, entry in enumerate(entries):
>     idx=i-(paginate_no-1)*paginate_limit
>     if 0<=idx and idx<=paginate_limit:
>          entry.viewed = 1
> return dict(entries=entries)
>   
with this solution you retrieve all the entries even if you display only 
a few of them.
You loose the fact that paginate can use an iterator that will retrieve 
only the displayed lines from the database.
> Remi, I like your solution, but prefere to use use a callable this
> way :
>
>
> @expose(...)
> @stats('entries', lambda x: x.viewed = 1)
> @paginate('entries', ...)
>
> with stats looking like :
>
> def stats(var_name, callable):
>    def decorator(func):
>         def wrapper(*args, **kw):
>              output = func(*args, **kw)
>             if var_name not in output:
>                 log.info(u"%s not in the result dict" % var_name)
>             else:
>                 resultat = output[var_name]
>                 for r in resultat:
>                     callable(r)
>             return output
>         return wrapper
>     return decorator
>   
Yes of course... My example was a very simple adaptation of my own stats 
function which is a bit more complicated ;-)

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears" 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?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to