Changing the parameters of a nested widget at display time

17 views
Skip to first unread message

BluePoint

unread,
Aug 23, 2008, 6:18:05 PM8/23/08
to ToscaWidgets-discuss
After searching the postings in this group and the similar TG group, I
have acquired only a hazy understanding of how to go about changing
the parameters of a child widget at display time and my attempts to do
it even in relatively simple cases have failed to achieve anything,
even when they did not cause syntax errors.

I and no doubt quite a few others would be grateful if someone who
does understand how it works could provide a clear statement of the
proper syntax of using child_args. In particular, since the children
are in a list, is it possible to access a particular child by its
index or must one always use its id? Also, can one access children of
children?

diefans

unread,
Aug 24, 2008, 2:59:32 PM8/24/08
to ToscaWidgets-discuss
I use it like this:

child_args = {'parent':{'options': parent_options},
'template':{'options':template_options},
'owner':{'options':[(u.user_id, u.user_name) for
u in User.query().all()]},
'group':{'options':[(g.group_id, g.group_name)
for g in Group.query().all()]},
'weight':{'options': range(-99,100)}
}
# where all children in this case are a SingleSelectField

# at the end I return the following dict:
return dict(form = form,
form_data = form_data,
child_args = child_args)


...and the templates contains the following:
${form.display(form_data, child_args = child_args)}

BluePoint

unread,
Aug 29, 2008, 1:50:54 PM8/29/08
to ToscaWidgets-discuss
Many thanks for that.It's a neat idea to prepare it all in the code
and just send a dict to the template. I will try something along those
lines.

BluePoint

unread,
Sep 12, 2008, 1:51:47 PM9/12/08
to ToscaWidgets-discuss
I understand it now. As well as getting the syntax right for the
child_args dict, two other things need to be in place. The parameter
needs to be included in an update_attrs call in update_params at some
level of the inheritance chain.
Secondly, the template needs to contain something like:

<py:for each = "child in children">
${child.display(value_for(child), **args_for(child))}
</py:for>
Reply all
Reply to author
Forward
0 new messages