iain duncan wrote:
> On Sat, 2007-15-12 at 23:28 +0000, Alberto Valverde wrote:
>> iain duncan wrote:
>>> I got toscawidgets working in the python shell ( as in I could call and
>>> render a widget ) and in the pylons simple toscawidget example, where
>>> the widget gets attached to that handy 'c' object. Couldn't figure out
>>> what to do in TG2 though. Doing the regular tg way gives me the
>>> following traceback from *paster* ( the browser screen just hangs )
>>>
>>> TypeError: No object (name: ToscaWidgets per-request storage) has been
>>> registered for this thread
>> Did you stack TW's middleware in middleware.py?
> 
> Ok, my fault! I mixed up mywidget.display() and mywidget.render() and in
> this case did not get a traceback as useful as the CP one. ( which
> complains about wrong return type when you do that ). Returning
> mywidget.render is working fine.

Aha, you were returning a genshi Stream object then... display() is to
be used when displaying a widget on a template or another widget since
display() tries to adapt the widget's output so multiple templating
engines can be mixed. Since you've configured the HostFramework with
default_view="genshi" then the widget, being a root widget, believes it
should return output suitable for displaying in genshi.

My guess is that the Stream was being iterated outside the Pylons
context hence the toscawidgets.hostframeowrk StackedObjectProxy was not
with the right context. But I'm digressing now... :)

If returning a widget's output directly you should also encode its
output since widgets always return unicode:

return widget.render().encode('utf8')

> 
> Now I dunno if anyone cares, but if you ( incorrectly ) try to return 
> mywidget.display() from a tg2 controller, the request hangs and paster
> chokes. Not immediately obvious what went wrong.

This error-checking should be done by Pylons if at all... It would
certainly be handy to assist in debugging.
> 
> So, I have a widget, (yay!) but I don't know how to validate it based on
> today's emails. Sounds like that is still up in the air a bit. Anyone
> got an example of any method that will work for the present to validate
> from a widget and redirect errors?

Take a look at this tutorial [1]. It's Pylons' specific but should work
in TG2 (albeit not with controller method's arguments but peeking
directly into the POST/GET params). This is a work-around until I
finally get to write the TG2 valdiate() version.

Alberto

[1] http://wiki.pylonshq.com/x/0YGq

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears Trunk" group.
To post to this group, send email to turbogears-trunk@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/turbogears-trunk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to