Re: [TurboGears] Re: Toscawidgets error

6 views
Skip to first unread message

Alberto Valverde

unread,
Apr 18, 2007, 3:36:40 PM4/18/07
to turbo...@googlegroups.com, toscawidge...@googlegroups.com

On Apr 18, 2007, at 8:57 PM, Dennis Muhlestein wrote:
> I thought for kicks I'd try out ToscaWidgets since they support
> Genshi.
>
> I tried to do a simple test of replacing the turbogears.mochikit with
> toscawidgets.widgets.mochikit.mochikit
>
> 1) easy_install ToscaWigets[genshi]
> 2) easy_install twMochikit
> 3) in my app.cfg
> toscawidgets.on = True
> tg.include_widgets = [ 'toscawidgets.widgets.mochikit.mochikit' ]
>
> Here is an excerpt from the log at application startup:
>
>>>> snip <<<
>>>>
> 2007-04-18 10:38:54,101 toscawidgets.view INFO Engine 'genshi-text'
> was succesfully initialized
> 2007-04-18 10:38:54,122 toscawidgets.view INFO Engine 'toscawidgets'
> was succesfully initialized
> 2007-04-18 10:38:54,127 toscawidgets.view INFO Engine 'json' was
> succesfully initialized
> 2007-04-18 10:38:54,143 toscawidgets.view INFO Engine 'genshi' was
> succesfully initialized
> 2007-04-18 10:38:54,165 toscawidgets.view INFO Engine 'genshi-markup'
> was succesfully initialized
> 2007-04-18 10:38:54,169 toscawidgets.view INFO Engine 'cheetah' was
> succesfully initialized
> 2007-04-18 10:38:54,186 toscawidgets.view INFO Engine 'kid' was
> succesfully initialized
> 2007-04-18 10:38:54,258 toscawidgets.mods.tg INFO Loaded TurboGears
> HostFramework
>
>>>> snip <<<
>>>>
>
> All good there it looks to me like.
>
> But when I try to view a page I get this:
>
>
>>>> snip <<<
>>>>
> File "/usr/lib/python2.4/site-packages/Genshi-0.4-py2.4.egg/genshi/
> template/base.py", line 431, in _eval
> File "/usr/lib/python2.4/site-packages/Genshi-0.4-py2.4.egg/genshi/
> template/base.py", line 397, in _eval
> File "/usr/lib/python2.4/site-packages/Genshi-0.4-py2.4.egg/genshi/
> template/base.py", line 441, in _flatten
> File "/usr/lib/python2.4/site-packages/Genshi-0.4-py2.4.egg/genshi/
> core.py", line 221, in _ensure
> File "/usr/lib/python2.4/site-packages/Genshi-0.4-py2.4.egg/genshi/
> input.py", line 41, in ET
> AttributeError: 'Stream' object has no attribute 'tag'
>
> Removing the widget from the include_widgets allows pages to display,
> but of course, I don't get the MochiKit JS link included.
>
> Is there a different way you are supposed to include ToscaWidgets on
> each page? Perhaps I missed a step somewhere.

> Alberto Valverde wrote:
>
>> You don't need the ET function to wrapToscaWidgets. Remove the
>> wrappers from your genshi site-template (where JS and CSS links are
>> included) and you should be fine.
>
> I still have some TG Widgets too though. Can I differentiate in the
> template which type of widget I'm working with and just add two
> methods for displaying?

Hmm, Yep, you could check for the "engine_name" attribute which only
TW has, something like:

def display_widget(widget, *args, **kw):
output = widget.display(*args, **kw)
if not hasattr(widget, 'engine_name'):
output = ET(output)
return output

Note, you only need to do this in page templates, not inside widget
templates as TW takes care of adapting output when children are
displayed inside a widget template.

Alberto

>
> PS.
> I discovered the toscawidgets-discuss list after I posted this. I'll
> move widget related conversation over there.

No prob. cross-posting there... (editing message to include full
conversation)

Dennis Muhlestein

unread,
Apr 18, 2007, 6:16:23 PM4/18/07
to ToscaWidgets-discuss
I solved the ET dilemma with tg widgets by modifying my site template
as follows:

<div py:for="js in tg_js_head" py:strip="True">
<script py:if="hasattr(js,'engine_name')" py:replace="js.display()" /
>
<script py:if="not hasattr(js,'engine_name')"
py:replace="ET(js.display())" />
</div>

When I get my stuff all converted, I can get rid of that so I'm not to
worried about it in the mean time.

Reply all
Reply to author
Forward
0 new messages