proper way to instantiate a widget with a specific set of data

0 views
Skip to first unread message

Jeremy Jones

unread,
Jan 6, 2006, 11:20:45 AM1/6/06
to turbo...@googlegroups.com
I have a TableForm with a bunch of TextFields (and other stuff...). I'm
trying to use it as the C and U prongs of the CRUD pitchfork. I've got
create working well. But how do I instantiate the TableForm and pass
it, say, a dict, and have it update the TextFields (and other stuff...)
with the data in the dict? this_table_form.input(some_dict) didn't
work. this_table_form.insert(input_values=some_dict) didn't work,
either. I tried mucking about in the fastdata source, but couldn't
figure out how it's being done there. Any tips would be greatly
appreciated.

Thanks,

- jmj

Soni Bergraj

unread,
Jan 6, 2006, 11:27:31 AM1/6/06
to turbo...@googlegroups.com
Hello,
TurboCheetah seems to have problems with extended templates. I created a
ticket for it (#360).

Cheers,

--
Soni Bergraj

Karl Guertin

unread,
Jan 6, 2006, 12:19:49 PM1/6/06
to turbo...@googlegroups.com

Widgets by default work thusly:

top_form = TableForm(name="top_form", widgets=(
TextField(name="alpha"),
TextField(name="bravo"),
TextField(name="charlie"))

...in an exposed method...

return dict(
data = {'alpha':1,'bravo':2,'charlie':3},
form = top_form,
)

...in your template...

${form.insert(data)}

The data is expected to be a class with attributes matching the names
in the form, but if you pass in a dict with the correct keys it gets
converted. The names in the data and on the text fields have to match.

Kevin Dangoor

unread,
Jan 6, 2006, 12:53:35 PM1/6/06
to turbo...@googlegroups.com
Actually, I'd really like it if someone else took over TurboCheetah.
Like, for example, someone who uses Cheetah :)

Especially now that the plugins are no longer tied to TurboGears or
CherryPy, it would be nice for its maintenance to move elsewhere...

Kevin


--
Kevin Dangoor
Author of the Zesty News RSS newsreader

email: k...@blazingthings.com
company: http://www.BlazingThings.com
blog: http://www.BlueSkyOnMars.com

Kevin Dangoor

unread,
Jan 6, 2006, 2:58:45 PM1/6/06
to turbo...@googlegroups.com
On 1/6/06, Soni Bergraj <ber...@aim.com> wrote:
>
> TurboCheetah seems to have problems with extended templates. I created a
> ticket for it (#360).

Hi,

I just took at a look at the ticket... Here's the explanation:
Yep. This is currently expected behavior. You can get around this by:

1. adding your template name to turbogears.view.baseTemplates.
2. calling turbogears.view.loadBaseTemplates()

This is all a matter of the fact that the template has not been
loaded/converted to Python. If you precompile your templates, it would
likely work.

Kevin

Soni Bergraj

unread,
Jan 6, 2006, 3:28:59 PM1/6/06
to turbo...@googlegroups.com
Hello again,

> I just took at a look at the ticket... Here's the explanation:
> Yep. This is currently expected behavior. You can get around this by:
>
> 1. adding your template name to turbogears.view.baseTemplates.
> 2. calling turbogears.view.loadBaseTemplates()

I added those two lines to my controllers.py:

turbogears.view.baseTemplates.append("cheetah:wiktory.templates.master")
turbogears.view.loadBaseTemplates()

but i still get the attached traceback.


> This is all a matter of the fact that the template has not been
> loaded/converted to Python. If you precompile your templates, it would
> likely work.

I'm working with precompiled templates. Do not precompiled templates
work at all?

Any ideas?

Thanks,

--
Soni Bergraj

Traceback

Kevin Dangoor

unread,
Jan 6, 2006, 3:34:11 PM1/6/06
to turbo...@googlegroups.com
On 1/6/06, Soni Bergraj <ber...@aim.com> wrote:
> I added those two lines to my controllers.py:
>
> turbogears.view.baseTemplates.append("cheetah:wiktory.templates.master")
> turbogears.view.loadBaseTemplates()

I wasn't clear enough, I think. Try extending wiktory.templates.master
in your Cheetah template.

Kevin

Soni Bergraj

unread,
Jan 6, 2006, 3:53:59 PM1/6/06
to turbo...@googlegroups.com
> I wasn't clear enough, I think. Try extending wiktory.templates.master
> in your Cheetah template.

An

#extends myproject.templates.master

instead of an

#extends master

finally works. And it is an amazingly 20 times faster than the kid
solution;)

Thanks for the hint:)

--
Soni Bergraj

Lee McFadden

unread,
Jan 17, 2006, 6:55:53 AM1/17/06
to turbo...@googlegroups.com
On 1/6/06, Karl Guertin <gray...@gmail.com> wrote:
>
> The data is expected to be a class with attributes matching the names
> in the form, but if you pass in a dict with the correct keys it gets
> converted. The names in the data and on the text fields have to match.
>

This still does not work for me. I'm currently using revision 514.

Have there been any further developments on this since r514?

Lee

Kevin Dangoor

unread,
Jan 17, 2006, 11:54:17 AM1/17/06
to turbo...@googlegroups.com
On 1/17/06, Lee McFadden <sple...@gmail.com> wrote:
>
> On 1/6/06, Karl Guertin <gray...@gmail.com> wrote:
> >
> > The data is expected to be a class with attributes matching the names
> > in the form, but if you pass in a dict with the correct keys it gets
> > converted. The names in the data and on the text fields have to match.
> >
>
> This still does not work for me. I'm currently using revision 514.

What does not work for you? Passing a dict?

Kevin

Lee McFadden

unread,
Jan 17, 2006, 12:00:07 PM1/17/06
to turbo...@googlegroups.com
On 1/17/06, Kevin Dangoor <dan...@gmail.com> wrote:
>
>
> What does not work for you? Passing a dict?
>
> Kevin
>

Yes, passing a dict does not work.

I have the following code (just to make sure it wasn't my controller
code messing things up)

<span py:replace="forwardform.insert(input_values={'fwd_msgid':
message.id, 'forward_to': ''}, action='/messages/%d/forward' %
message.id)"></span>

for the following widget:

forwardform = widgets.TableForm(widgets=[
widgets.TextField(name="forward_to",
labeltext="Forward To", validator=validators.Email()),
customwidgets.Hidden(name="fwd_msgid",
validator=validators.Int())],
submittext="Forward")

The widgets in customwidgets are the same but have custom templates.

I get no VALUE parameter in the resulting hidden field in the page.
I've tested this with more complex forms with the standard widgets
with the same result. The value is always omitted.

Kevin Dangoor

unread,
Jan 19, 2006, 10:19:27 AM1/19/06
to turbo...@googlegroups.com
On 1/17/06, Lee McFadden <sple...@gmail.com> wrote:
> Yes, passing a dict does not work.
>
> I have the following code (just to make sure it wasn't my controller
> code messing things up)
>
> <span py:replace="forwardform.insert(input_values={'fwd_msgid':
> message.id, 'forward_to': ''}, action='/messages/%d/forward' %
> message.id)"></span>

Try getting rid of the "inpuit_values=". If you pass the form widget a
dictionary as its value, that should get applied.

Kevin

Reply all
Reply to author
Forward
0 new messages