ob1.data schrieb:
> <body>
>     ${tmpl_context.testwidget.display()}
> gives me UndefinedError: '' has no member named "display"
> 
> 
> class TestWidget(Widget):
>     javascript = [ JSLink(link=url('/js/chart.js')) ]


Don't do this, use the modname/filename variant. The reason is that 
tg.url can't work on module-import-time, as it needs access to the 
environment to really work, and that's only available in a request.

And even if tg.url would work, overall it's not working because 
"/js/chart.js" is a relative path to something the system doesn't 
recognize - unless you have a js-named controller on your root, and a 
chart_js-action on that. Which you don't have I presume.

BTW, in my example I used the modname/filenam-variant. Why did you 
change it? And did it work for you?

>     template = "pkg.templates.widgettest"
>     engine_name = "genshi"
> 
>     def __init__(self, name):
>         super(TestWidget, self).__init__(self)
> 
>     def update_params(self, d):
>         super(TestWidget, self).upadate_params(d)
>         #I read that this must be done explicitly
>         self.add_call(javascript)
>         #Invoke javascript from myscript.js here?
>         #But won't this re-inject the JS for
>         #every rendering? I thought I read TG's
>         #smart enough to do it just once if I ...?

Again this seems to be some exercise in genetic programming. Yes, TW 
*is* smart enough to inject the resoure.

It is also smart enough to insert the add_call, but that's supposed to 
contain a string that will be rendered like a JSSource-widget, and it 
should contain some widget-specific code, such as

self.add_jall("""$(document).ready(function() {
     $("#%s").do_something();
})""" % d.id)

And where does the "javascript" come from?

> testwidget = TestWidget("TestTW")
> 
> 
> @expose('pkg.templates.widgettest')
> def widgettest(self, **kw):
>     pylons.c.widgettest = testwidget
>     return dict(form=testwidget)  #, action=blah, value=blah)


Both the widget and the controller share the same template? How's that 
supposed to work? Either you are not rendering a full HTML-page, then 
the resource injection of course can't work (it needs 
html/head/body-tags), or you rendering those *twice*

> 
> <body>
>     <p py:content="form.display(submit_text='Yes')">
>        Widget Form</p>
> gave me UndefinedError: "tg" not defined
> 
> 
> The above code works in the sense that there
> are no errors thrown.   Clicking on the link
> for my controller method 'widgettest' renders
> the page with title and the text in the div
> that is supposed to be replaced.  But no JS
> action occurs onscreen.  :{

As you don't show us the template, I can't comment on that.


> 
> PS.
>  There is nothing in the rendered page's
> source <head> section resulting.
> 
> Putting the code below into the template works
> in so far as it appears if I View Page Source.
> However, nothing happens, the JS does not
> appear to run.
>   <script type="text/javascript" src="${tg.url('/js/chart.js')}"></
> script>

IT does not do something for the reasons explained above - /js/chart.js 
isn't delivered by the system.

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