toscawidgets.form.DataGrid and friends

11 views
Skip to first unread message

Jonathan Wight

unread,
Dec 9, 2006, 4:05:31 PM12/9/06
to turbo...@googlegroups.com
A bunch of toscawidget questions:

1) I'm having no luck getting a toscawidgets.form.DataGrid to work
using much the same mechanism I would use with
turbogears.widgets.DataGrids:

I'm using the latest toscawidgets* from the Python cheese shop.

Simple code like:

@expose(template="cocoahaus.templates.test")
def index(self, *args, **kwargs):
theFields = [('Key', 'Value'),]
theGrid = toscawidgets.form.DataGrid(name = 'grid', fields =
theFields)
return dict(grid = theGrid, data = gridData)

Will consistently give me this error:

Page handler: <bound method Test.index of
<cocoahaus.controllers.Test.Test object at 0x25a60b0>>
Traceback (most recent call last):
...
File "build/bdist.darwin-8.8.1-i386/egg/genshi/core.py", line 202, in
_ensure
File "build/bdist.darwin-8.8.1-i386/egg/genshi/plugin.py", line 29,
in ET
AttributeError: 'str' object has no attribute 'tag'

2) If I want to modify a widget to use my own genshi template is it
merely a case of something like this:

class MyDataGrid(toscawidgets.forms.DataGrid):
template = "genshi:cocoahaus.templates.widgets.MyDataGrid"

3) Are toscawidgets going to replace the turbogear's widgets - and if
so, in what time frame?

Cheers.

Jon.

Alberto Valverde

unread,
Dec 10, 2006, 7:18:41 AM12/10/06
to turbo...@googlegroups.com

>
> A bunch of toscawidget questions:
>
> 1) I'm having no luck getting a toscawidgets.form.DataGrid to work
> using much the same mechanism I would use with
> turbogears.widgets.DataGrids:
>
> I'm using the latest toscawidgets* from the Python cheese shop.
>
> Simple code like:
>
> @expose(template="cocoahaus.templates.test")
> def index(self, *args, **kwargs):
> theFields = [('Key', 'Value'),]
> theGrid = toscawidgets.form.DataGrid(name = 'grid', fields =
> theFields)
> return dict(grid = theGrid, data = gridData)
>
> Will consistently give me this error:
>
> Page handler: <bound method Test.index of
> <cocoahaus.controllers.Test.Test object at 0x25a60b0>>
> Traceback (most recent call last):
> ...
> File "build/bdist.darwin-8.8.1-i386/egg/genshi/core.py", line 202, in
> _ensure
> File "build/bdist.darwin-8.8.1-i386/egg/genshi/plugin.py", line 29,
> in ET
> AttributeError: 'str' object has no attribute 'tag'

It seems there's something wrong with the conversion "display" does to
support mixing template languages. Can you please post the full traceback
and the template language of the template you're trying to display the
grid on?

The TurboGears HostFramework object that interfaces ToscaWidgets with TG
uses the tg.default_view config option to "guess" this but could guess
wrong if it's not correct (this part needs some more work...). You can
tell "display" what language to display the widget on by passing the
"_dest" kw arg:

grid.display(data, _dest='genshi')

to display on Genshi (or set tg.default_view = 'genshi' if all your page
templates are written in genshi).

BTW, the "name" argument is not used anymore... Pass it as the "id" kw arg
or as the first positional arg.

An another thing which might bite you (and others): In
turbogears.widgets.DataGrid you could pass a function that returns an
ElementTree instance to build each column. Now that the grid defaults to
genshi you can no longer do that. You should wrap that Element tree
instance in genshi.plugins.ET if you want to use that method or, better
still, pass a widget instance to display each cell (this method has a
little gotcha I shall explain better in the docs or when someone really
gets bitten ;)


> 2) If I want to modify a widget to use my own genshi template is it
> merely a case of something like this:
>
> class MyDataGrid(toscawidgets.forms.DataGrid):
> template = "genshi:cocoahaus.templates.widgets.MyDataGrid"

Yep, that is correct. You could also pass it as an arg. to the constructor
if you don't want to subclass.


> 3) Are toscawidgets going to replace the turbogear's widgets - and if
> so, in what time frame?

TurboGears 2.0 will have a major overhaul splitting most of its
functionality into separate independently mantained packages which should
make reuse in other frameworks easier. Answering your question: yes, in
TurboGears 2.0.

Alberto

Reply all
Reply to author
Forward
0 new messages