Arguments to a callable parameter

13 views
Skip to first unread message

Antoine Pitrou

unread,
Nov 19, 2009, 2:20:26 PM11/19/09
to ToscaWidgets-discuss
Hello,

I need to populate a RadioButtonList with different options depending
on the object which is being edited (some objects will have more
options offered than others). Of course the object id is part of the
form (as a HiddenField), but looking at the doc (*) it seems that a
callable parameter isn't given any arguments when it is called. Which
means that I don't have enough context information to know what values
to return exactly.

(I worked around this by reading the context directly from the pseudo-
global `request` variable supplied by TurboGears but this is not very
pretty IMHO)

Regards

Antoine.

(*) http://toscawidgets.org/documentation/ToscaWidgets/usage.html#callable-parameters

cd34

unread,
Nov 19, 2009, 11:14:39 PM11/19/09
to ToscaWidgets-discuss
Here's how I handled it in TG2 a while back when I ran into the same
issue.

http://cd34.com/blog/programming/python/turbogears-tableform-and-a-callable-option-to-a-widget/

Diez B. Roggisch

unread,
Nov 20, 2009, 3:41:02 AM11/20/09
to toscawidge...@googlegroups.com
Antoine Pitrou schrieb:
> Hello,
>
> I need to populate a RadioButtonList with different options depending
> on the object which is being edited (some objects will have more
> options offered than others). Of course the object id is part of the
> form (as a HiddenField), but looking at the doc (*) it seems that a
> callable parameter isn't given any arguments when it is called. Which
> means that I don't have enough context information to know what values
> to return exactly.
>
> (I worked around this by reading the context directly from the pseudo-
> global `request` variable supplied by TurboGears but this is not very
> pretty IMHO)

You should be able to actually set the options via the
update_params-call of the Form itself. I'm not 100% positive about this,
but it *should* work like this:



class MyForm(TableForm):
...


def update_params(self, d):
super(MyForm, self).update_params(d)
# this should actually check the
# existence of child-args first I guess.
d.child_args["radio_button_list_widget_name"] = dict(options=
options_by_id(d.value_for("hidden_field_name"))


I'll try to throw together a working example if I find the time.

Diez
Reply all
Reply to author
Forward
0 new messages