Thanks Alessandro.
SQLAlchemy won't work in my case - there's some processing involved beyond the 
scope of the database, which obviously I didn't mention in my original post. 

The before_render hook however works like a charm. (thumbs up icon here)

Uwe



On Sun, 06/15/2014 06:56:09 PM Alessandro Molina wrote:
> Best solution is probably to rely on SQLAlchemy relationship features to
> fetch them. If you emit a "joined" relationship the comments for the posts
> loaded in current page will automatically be loaded with the blogs.
> 
> About accessing the paginated data, it is accessible inside the
> before_render hook, just apply a @before_render decorator before the
> @paginate decorator so it gets executed after pagination.
> 
> On Sun, Jun 15, 2014 at 9:10 AM, Uwe Schroeder <[email protected]> wrote:
> > Does anyone know whether it's possible to access a decorator's attributes
> > inside the decorated method?
> > 
> > My problem:
> > 
> > I have blogs and the blogs can have comments. The blogs are the collection
> > used in the pagination decorator., i.e.
> > 
> > @paginate("blogs", items_per_page=3)
> > 
> > def blogs(self):
> >   return dict(blogs=fetchblogsfromdatabase())
> > 
> > What I want to do is grab the blog comments only for the blogs currently
> > displayed on the paginated page. Aka:
> > 
> > @paginate("blogs", items_per_page=3)
> > 
> > def blogs(self):
> >   blogs=fetchblogsfromdatabase()
> >   comments=dict()
> >   
> >   for x in blogs[on_current_page]:
> >       comments[x.id]=grab_comments_for_x.id_blog()
> >   
> >   return dict(blogs=blogs, comments=comments)
> > 
> > Obviously the decorator grabs the "blogs" collection after the controller
> > returns to hand the resulting subset to the templating engine.
> > 
> > Is there a hook I could use to inject the comments between decorating and
> > rendering?
> > 
> > Well, the other method would probably be an ajax call after rendering
> > without
> > the comments to grab the comments and inject them into the page.
> > 
> > Any bright ideas on how to accomplish this? Ideally I'd like to access the
> > "paginate.items" attribute inside the controller method - but at that time
> > the
> > decorator doesn't even know anything about the items to be rendered yet...
> > 
> > Thanks for any helpful hints anyone here might have.
> > 
> > Uwe
> > 
> > --
> > You received this message because you are subscribed to the Google Groups
> > "TurboGears" group.
> > To unsubscribe from this group and stop receiving emails from it, send an
> > email to [email protected].
> > To post to this group, send email to [email protected].
> > Visit this group at http://groups.google.com/group/turbogears.
> > For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/turbogears.
For more options, visit https://groups.google.com/d/optout.

Reply via email to