As it turns out, when you create your form widget:
the field class gets created once, at the controller load, and that's it.editform = widgets.TableForm(
fields=EditFields(),
action="/editsave")
Therefore, if you populate your fields when you create the form, they won't be updated, possibly causing you to learn more than you wanted to about SQLObject caching. I found the solution on this page. Similar to passing values, you just pass a dictionary of the options to the appropriate widget. Since I have a generic CRUD controller, I created a function in my EditFields class that returns a dictionary of all the options fields and updated values, like so:
(using the build_list method here) then, in my controller:def updatelists(self):
"""Return a dictionary of any lists
that need to be updated due to new objects"""
companylist = Company.build_list(
'name',
orderBy=Company.q.name)
#in my form, companyID is the
#name of the SingleSelectField
return dict(companyID=companylist )
and finally, in my model:return dict( form=self.editform,
values=objvalues,
options=self.fieldswidget.updatelists())
(I'm using Genshi, which is why I have the ET function there)<div py:content="ET(form.display(
value=values,
options=options))">
No comments:
Post a Comment