“searchhi” wrapped using ToscaWidgets

by gldnspud on December 31, 2006

{ 1 comment }

Alberto January 2, 2007 at 12:35 pm

Hi Matthew,

Just some comments on your code:

1) I see that you’re relying on the widget’s __str__ method when displaying a widget inside another. I wouldn’t recommend that because you’re depending on the fact that both the JSSource and your widget use string.Template plain string templates and that won’t play nice when mixing with widgets that have Genshi or Kid templates which produce streams.

The correct way to do it is using widget.display(…) or it’s shortcut widget(…) (don’t use “render” inside widget templates) *and* setting the inner widget as a child of the container (this is needed so “display” knows how to translate between Genshi/Kid streams, plain strings or whatever the template engine that might come up next produces…).

2) The JSSource you’re displaying will not appear in body-bottom (unless you’re doing something to explicitly place it there). To make it appear there I’d recommend subclassing JSSource directly for for the SearchHighlighter. Resources (Links and Sources) are displayed with no parameters so you can omit the the update_params method and do everything inside __init__. To use it just instantiate it with the required params and place it in c.w so retrieve_resources will fetch it and the master template puts it in bodybottom.

3) To escape strings for generating javascript on the fly I’d recommend JSON encoding them with SimpleJson (or python-cjson, a JSON en/decoder written in C which I haven’t tried yet but looks promising)

I’ve written an Image widget (regarding your other post @ http://goldenspud.com/rotr/index.php/2006/12/28/taking-toscawidgets-for-a-spin)
with some tweaks I had to do the widget API because a hack I did to the Links to support positional parameters at the constructor (besides the usual (id, parent, children)) screws everything up when you need to actually pass an id or set a parent. I’ll post a link to it in the other article as soon as I place it somewhere publicly accesible and comit some changes to TW. For the meantime I’d recommend changing your JSLink and CSSLink instantiations to use kw. args (modname and filename) so they won’t break when I change that.

Regards,
Alberto

Comments on this entry are closed.

Previous post:

Next post: