On 1/2/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> def whatever(self, **kw):
>     foo = widgets.TextField('bar')
>     if kw.get('something'):
>         foo.attr['class'] = 'one'
>     else:
>         foo.attr['class'] = 'two'
>     ...
>
> Is it really the case that the above is not threadsafe? If not, where
> in the request cycle does the widget become (potentially) shared --
> only inside of the template? Or am I just misunderstanding something?

It's really very similar to a cherrypy controller. You can't use
"self" attributes in a cherrypy controller because the same controller
instance is used for each request. Consider how a form is used:

myform = TableForm([TextField("name"), TextField("address")])

class MyController(controllers.Controller):
    @turbogears.expose(html="my.template")
    def index(self):
        return dict(form=myform)

    @turbogears.expose(inputform=myform)
    def save(self, name, address):
        ...

You don't get a new form for each request. So, as it stands now,
widgets are stateless. The parameters that define the basic properties
of a widget that are the same over and over are sent in via the
constructor. The options that can change from request to request are
sent in via render() or insert().

This is something that I've seen trip people up a couple of times
already. That may partly be because there's no widget documentation
yet. But, we can think about the implications of making widgets get
instantiated for each rendering.

Kevin

--
Kevin Dangoor
Author of the Zesty News RSS newsreader

email: [EMAIL PROTECTED]
company: http://www.BlazingThings.com
blog: http://www.BlueSkyOnMars.com

Reply via email to