views:

65

answers:

2

Hi to all,

For my site need some "widgets" that elaborate output from various data models, because this widgets are visible in any page is possible with mako to retrieve the data without pass (and elaborate) every time with render() in controllers?

A: 

It sounds like you're looking for some combination of FormAlchemy, ToscaWidgets and/or Sprox. I would check out those three.
Also, you might read Chapter 6 of http://pylonsbook.com/en/1.1/ . It helped me a bunch; maybe you'll get something out of it as well.

yarmiganosca
sorry, the word "widget" is ambiguous, in my case widgets are pieces of code html generates with data not related at a single controller action. ex: last tweets box in a blog, i need to not add twitter api logic code in any action controller.
Angelbit
@Angelbit: Then you're probably just stuck with writing a method (tied to a particular template fragment) for each "activity" (i.e. last tweets box) and composing them together into a page. Also, you probably don't actually want the templates to talk to the data layer directly (hinders reusability).
yarmiganosca
I'm want templates than talk with a function used as simple controller layer, this function return data to Mako for generate the "widget" html code.
Angelbit
+1  A: 

May be you need use helpers

in lib/helpers.py

def tweets(**params):
   context = {}
   return render('tweets.mako', context)

In you page template do this to render you tweets widget:

   h.tweets()
estin