Neil Tiffin schrieb:
> My problem.
>
> Use a session value as part of a select statement to determine what
> is shown in a SingleSelectField on a form.
>
> The current problem is getting the session data to be recognized when
> setting up the widget named "Task Name". I assume that I have to
> request the data for the widget in the Kid template instead of during
> initialization, But I am not sure how to do this or even if this is
> the correct approach.
>
> from Controllers.py (non-relevant removed)
> ==============
> name_list = people.build_list('name', orderBy=people.q.name)
> project_list = project.build_list('name')
>
> class ProjectFields(widgets.WidgetsList):
> w_project = widgets.SingleSelectField(label="Project Name",
> options=project_list, default=1)
>
> class TimeFields(widgets.WidgetsList):
> w_name = widgets.SingleSelectField(label="Person Name",
> options=name_list, default=1 )
> w_days = widgets.TextField(label="Days Charged", default="1.0")
> w_task = widgets.SingleSelectField(label="Task Name",
> options=lambda:[(p.id, p.taskName) for p in task.select
> (task.q.projectID==cherrypy.session['cur_project'],
> orderBy=task.q.taskName)])
>
> time_form = widgets.TableForm(fields=TimeFields(), action="save")
> project_form = widgets.TableForm(fields=ProjectFields(),
> action="changeProject")
This can't possibly work - you have a major conceptual flaw here: a
widget like this, which is created at startup-time as a single object,
can't possibly have state that is dependent on user-interaction later
on. You either have to:
- return a fresh widget instance per user-request
- pass the varying information somehow down to the rendering code.
The first solution is easy, but potentially wasteful: create a new
TimeFields-instance for each request.
The second one I'm a bit unsure right now. Usually, one can pass
parameters to widget.display that are available as "value" when
rendering. This is the case for SingleSelectField as well.
So if you had only this single-select-field, it would look like this:
${select_field.display(optionlist)}
Ok - I just had a look into the TableForm-code, and it appears that the
method
value_for
from CompoundInputWidget is called. This will fetch the value for the
sub-widget from a path that should look like this
('w_task', None)
So it should work for your compound widget above, if you pass the value
like this:
time_form.display({'w_task' : optionlist})
HTH,
Diez
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---