Hi all,
I'm new to Turbogears, and am loving it. I get the basics pretty
well, but am attempting my first bit of Ajax, and am completely stuck.
I'm basically just displaying info from a database that was populated
from elsewhere. That works fine. But now I'm trying to add a dynmaic
checkbox that corresponds to a field in the DB.
When displaying the page, the checkboxes default state should
correspond to its state in the database. 0 for unchecked, 1 for
checked. Then, the user should be able to toggle the checkbox and the
new state auto-ajaxically updated in the database.
Here's what I have so far:
Controller
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
class Root(controllers.RootController):
@expose(template="audiotic.templates.files")
def index(self):
files = model.Files.select(orderBy="date").reversed()
checkbox = widgets.CheckBox(name="pass_qc", default=False,
help_text=None)
return dict(files=files, checkbox=checkbox)
Template
~~~~~~~~~~~~~~~~~
<body>
<table border="1">
<th>File</th><th>Status</th><th>Last Updated</
th><th>Error Code</th><th>Pass QC</th>
<tr py:for="file in files">
<td>${file.filename}</td>
<td>${file.state}</td>
<td>${file.date}</td>
<td>${file.errno}</td>
<div py:if="file.pass_qc == 0">
<?python checkbox.default=True ?>
</div>
<td>${checkbox.display()}</td>
</tr>
</table>
</body>
</html>
At this point I'm just trying to load the default value into the
checkbox widget, but it won't let me. I get "ValueError: It is not
threadsafe to modify widgets in a request" I searched on that error,
and found quite a few hits, but no examples that I could learn from.
Could someone please show an example of how I can accomplish this?
I'm also not sure where to start on the Ajax bit. I investigated
RemoteForm and RemoteLink, but I can't make sense of them.
Also, is it a problem that I'm only instantiating one checkbox widget
with the same name many times? Do I need to dynamically change the
name or id of the widget as well so that it links up to the correct
entry in the database?
Please help and TIA!
~Sean
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---