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/fdff4064fdf809b1

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)


In my controller method in root.py I have ...
=============================================
    @expose("pkg.templates.pic")
    def pic(self, **kwargs):
        """
        This is where we attach the form to pylons.c.something and
whatever
        you attach will be available in the template as
tmpl_context.something
        """
        pylons.c.test_pic = test_pic
        return dict(wikipage='pic')


But templ_context.test_pic is not available. :-(

"UndefinedError: "templ_context" not defined"
...
Module genshi.template.base:520 in _eval          view
Module genshi.template.base:286 in _eval_expr         view
Module genshi.template.eval:180 in evaluate         view
Module ?:25 in <Expression u'templ_context.test_pic()'>         view
<<      --><!-- OK, addressbook way - I have a form called
test_pic...-->
           <p>${templ_context.test_pic()}</p>
       </body>
       </html>
>>  <p>${templ_context.test_pic()}</p>
Module genshi.template.eval:306 in lookup_name         view
Module genshi.template.eval:405 in undefined         view
UndefinedError: "templ_context" not defined

I've tried importing both templ_context and pylons.c in root.py and in
the widget module.  Where should it be imported as what?
--~--~---------~--~----~------------~-------~--~----~
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