When using the SelectShuttle as a widget, how do you update the "available" and "selected" fields in the template?
I dynaimcally populate the two lists and after the second submission I get the following error:
for_widget.available_options = self.availableRestarting the cherrypy instance is the only way to get the site going again...
File "/usr/lib/python2.4/site-packages/TurboGears-0.9a8-py2.4.egg/turbogears/widgets/base.py", line 270, in __setattr__
raise ValueError, \
ValueError: It is not threadsafe to modify widgets in a request
Any help would be greatly appreciated.
Thanks, Andrew.
Here is the code I am having trouble with...
Controller Code:
for_widget = SelectShuttle(
name="select_clusters",
label = "The shuttle",
title_available = "Unallocated Branches",
title_selected = "Selected Branches",
form_reference = "document.forms['%s']" % form_ref,
# All data should be provided as a list of tuples, in the form of
# ("id", "value"). ATM, id should be an int
available_options = [],
default = dict(selected=[])
)
# Dummy form just so we can validate input
validating_form = widgets.Form(fields=[for_widget])
class Root(controllers.RootController ):
....
@expose(template=".templates.cluster_edit")
def cluster_edit(self, cluster):
"""
Show the Allocated and Unallocated branches for this cluster
"""
self.available=[]
self.selected=[]
self.available_branches = Branch.select_by(br_active = True, br_cluster_brn = 0)
self.selected_branches = Branch.select_by (br_active = True, br_cluster_brn = str(cluster))
for row in self.available_branches:
log.debug( "Available Data: [%s, %s, %s, %s]" % (row.br_cde, row.br_desc, row.br_active , row.br_cluster_brn) )
self.available.append((int(row.br_cde), "%s %s" % (row.br_cde, row.br_desc)))
for row in self.selected_branches:
log.debug( "Selected Data: [%s, %s, %s, %s]" % ( row.br_cde, row.br_desc, row.br_active, row.br_cluster_brn) )
self.selected.append((int(row.br_cde), "%s %s" % (row.br_cde, row.br_desc)))
#self.for_widget = for_widget
for_widget.available_options = self.available
for_widget.default = dict(selected = self.selected)
#validating_form = widgets.Form(fields=[for_widget])
return dict(for_widget=for_widget, cluster = cluster)
.....
Template Code:
<form action="" name="remote_form_select_shuttle" method="POST">
${for_widget.display()}<br />
<input type="hidden" name="cluster" value="${cluster}" />
<center><input type="submit" value="Submit" /></center>
</form>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

