On Monday 13 July 2009 07:19:20 ob1.data wrote:
> OK, so I numptied the constructor but ultimately I do want to fill
> from the DB.  Anyway, I've removed the __init__ and fixed some minor
> HTML syntax and then the next error did look like it was about Tosca
> Widgets.
> "WidgetLocked:...It's unthread-safe to alter it's attributes after
> initialisation."
>
> I read somewhere that widgets are stateless and can be shared between
> threads and I might well be wanting to do that. So I put the inject
> call in the __init__ of my form.  I'd had test_pic.title="The Plot" in
> my controller, so clearly I'd lost the plot ;-)
>
> Reading the address book example, I see that we no longer have to
> return a dict but can just go 'pylons.c.something = something' and my
> form will be available in my template as 'templ_context.something'.
> Well and good, it seems that a consensus _may_ be emerging on 'passing
> tw forms to templates' --see
> http://groups.google.com/group/turbogears-trunk/browse_thread/thread/fdff40
>64fdf809b1
>
> But where does this magical templ_context come from?  I gather it's a
> TG thing and is the same as pylons.c but what's the "one-- and
> preferably only one --obvious way" to inject JS resources?  Am I close
> to having done it correctly yet?
>
>
> In /templates I now have...
> ===========================
>    <h1>The Plot</h1>
>    <br/>
>    <div id="testUpdating" style="width: 300px; height: 300px;">
>        This text will be replaced by a chart, I hope...
>    </div>
>    <p>${templ_context.test_pic()}</p>
>
>
> In /widgets I have...
> =====================
> class TestPic(TableForm):
>     template = "pkg.templates.pic.html"
>     #js = [JSLink(link=url('/public/js/chart.js'))]
>     #gav Hmmm, not so sure where to do this
>     class fields(WidgetsList):
>          id = TextField()
>          title = TextField()
>          fig = TextArea()
>
>     def __init__(self, template):
>         JSLink(link=url('/public/js/chart.js')).inject()
>         #gav But how do these two lines join up?
>         inject_resources(template)

This is not correct. The method to do such stuff is "update_params", precisely 
because of the statelessness of widgets - the constructor is only called once 
per process (or at least supposed to, and things might break otherwise), and 
as the injection has to take place on each request, you need to use 
update_params.

Diez


--~--~---------~--~----~------------~-------~--~----~
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