ob1.data schrieb:
> Ok, thanks Diez.
>
> I renamed class TestPic(TableForm) to PicForm
> and now it goes a little something like this:
>
> ===================================================
> class PicForm(TableForm):
> #js = [JSLink(link=url('/public/js/chart.js'))]
> #gav Hmmm, not too sure where to do this.
> params = ["template", "js"]
> template = "pkg.templates.pic.html"
> js = [JSLink(link=url('/public/js/chart.js'))]
>
> class fields(WidgetsList):
> id = TextField()
> title = TextField()
> fig = TextArea()
>
> #After init, widget is shared so mods not thread-safe
> #def __init__(self, template):
> #JSLink(link=url('/public/js/chart.js')).inject()
> #inject_resources(template) #The new way tw does it
>
> #If you need to fetch data from external sources, do it here
> #http://toscawidgets.org/documentation/ToscaWidgets/modules/
> api.html
> def update_params(self, d): #d is a dict with all args stuffed in
> it.
> super(PicForm, self).update_params(d) #Must do this
> explicitly
> d.js = JSLink(link=url('/public/js/chart.js')).inject()
> d.template = "pkg.templates.pic.html"
> #inject_resources(template) #gav But no params allowed
> here!
> #Now create an instance of this form
> pic_form = PicForm("pic_form") #gav What is this parameter for?
> ===============================================================
>
> I thought TG was supposed to make the front end dev easy. Ye olde PL/
> SQL
> with all HTML inside "..." would be easier to follow. Hopefully the
> power
> and beauty of the MVC structure of all this stuff is going to kick in
> any day now. Am I the only newbie struggling with this kind of
> stuff?
Well, I'm not sure, but you seem to take a rather strange approach of
working with TG (or TW, in this case). It appears as if you formed an
idea of how things should work by some snippets of documentation, and
then start building wildly on them.
Take the above: you somehow are aware that there is a possibility to
declare JS-dependencies, and that there is injection. And you mix that
together to something that is looking awful, and not working ...
This is not meant to be offensive - it's just something I've noted. And
so far, I haven't seen anybody else doing this. But then, I've certainly
not seen all newbie code.
So for the above:
- the classlevel-attribute "js" is not known to TW. It's called
"javascript"
- the template is not defined inside update_params.
- update_params is not a general replacement for the constructor -
it's just for the *dynamic* parts of a widget, and to prepare stuff for
the template namespace.
- templates are given without their extension.
So with what I can grasp from the above, I'd say what you want looks
like this:
class PicForm(TableForm):
engine_name = "genshi" # sometimes this is needed for me, maybe you
can get aloning without it
template = "pkg.templates.pic" # no need for html here, causes the
error you see
javascript = [JSLink(link=url('/public/js/chart.js'))]
class fields(WidgetsList):
id = TextField()
title = TextField()
fig = TextArea()
And yes, I think that's rather beautiful compared to PL/SQL mixed with HTML.
> Maybe not, as I see there was some fairly extensive discussion on tg-
> trunk
> re. this update_params stuff.
>
> Now I get another ImportError. Is it because I haven't injected
> because
> no params are allowed in update_params? If so, where/how can I put
> the call
> to inject_resources?
You usually don't do that. TW does that for you, **if** you declare them
properly.
Resource injection is only needed if you want something inside the page
that isn't a dependency of some other wiget that gets called it's
display()-method.
>
> ======================================================
> Module ?:27 in <Expression u'tmpl_context.pic_form()'> view
> << pic_form with template = "pkg.templates.pic.html"
> This seems to want a 'pic' module. I have one in /
> model -->
> <p>${tmpl_context.pic_form()}</p>
> <!-- :-( ImportError on module pic ...?! -->
You have a pic-subpackage by declaring a template
"pkg.templates.pic.html" because the html is superflous, and assumed to
be actually a file called "html.html" inside a module called pic.
HTH,
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
-~----------~----~----~----~------~----~------~--~---