Monday, September 24, 2007

Gotcha: Toscawidgets and Mochikit

So, after much annoyingness, I've finally realized why I was having so much trouble using the Mochikit extension to Toscawidgets. As the Toscawidgets docs state, you need to include this template if you're using Genshi, which basically adds these lines (plus matching matching body top and bottom lines):

<link for=\"css in tg_css\" replace=\"css.display()\">
<link for=\"js in tg_js_head\" replace=\"js.display()\">

Now, if you're silly, like me, and don't really pay attention, you just include it, without looking too hard at your master template, which includes these lines by default:

<link for=\"css in tg_css\" replace=\"ET(css.display())\">
<link for=\"js in tg_js_head\" replace=\"ET(js.display())\">

As soon as you put the widget in your controller:

from toscawidgets.widgets.mochikit import mochikit
class Root(controllers.RootController):
@expose("genshi:mumapp.templates.sections")
def info(self):
return dict( form = InformationForm,
js = mochikit )

You start to get funny Genshi errors, mine was "AttributeError: 'Stream' object has no attribute 'tag'" which prompted me to try various combinations of adding ET() and HTML() to my templates, when the problem was that Toscawidgets cleans that whole ET/Genshi issue up and breaks when you leave them in.

So, long story short, add the site template and remove the conflicting lines from your master template. (Though, if you are mixing Toscawidgets and Turbogears widgets, you'll have to do something like what's outlined here.)

No comments: