On Sep 6, 4:16 am, "Florent Aide" <[EMAIL PROTECTED]> wrote:
> > <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>
> > <td>${checkbox.display(value=file.pass_qc==0)}</td>
> > </tr>
> > </table>
> > </body>
>
> As a side note I would recomment you use a slightly different syntax
> for your kid template. In place of
>
> <td>${file.filename}</td>
>
> I would use
>
> <td py:content="file.filename">file name here</td>
>
> Basically try to replace any $variable by py:content="variable" declarations.
> This is cleaner xml wise, will work with HTML editors _and_ will
> optimize your rendering speed a little bit.
>
> Cheers,
> Florent.
Thanks Florent.
I'll make the changes you mention about py:content. At this point I'm
just trying to get things working. Which I managed to do after a day
of fiddling. I got the Ajax part to work as well, but I'm sure I'm
not doing it the TurboGears way and I'm not using MochiKit. What is
the idiom for accomplishing this sort of thing using the right tools?
Controller
~~~~~~~~~~~~~~~~~~~~~~
class Root(controllers.RootController):
@expose(template="audiotic.templates.files")
def index(self):
files = model.Files.select(orderBy="date").reversed()
checks = []
for file in files:
checks.append(widgets.CheckBox(name="pass_qc_%s" % file.id,
default=file.pass_qc, help_text=None,
attrs=dict(onClick="startRequest('GET', 'db_toggle_qc?id=%s');" %
file.id)))
return dict(checks=checks, files=files)
@expose()
def db_toggle_qc(self, id):
a = model.Files.select("id="+str(id))
a = a[0]
if a.pass_qc in [0, None]:
a.qc_state = "PASSED"
a.pass_qc = 1
a.errno = None
else:
a.qc_state = "FAILED"
a.errno = 40
a.pass_qc = 0
return dict()
template
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
...
<script type="text/javascript" src="static/javascript/
AjaxRequest.js"></script>
...
<tr py:for="file, checkbox in zip(files, checks)">
<td py:content="file.filename">filename</td>
<td py:content="file.state">state</td>
<td py:content="file.date">date</td>
<td py:content="file.errno" align="center">errno</td>
<td py:content="file.qc_state"
align="center">qc_state</td>
<td py:content="checkbox.display()"
align="center">checkbox</td>
AjaxRequest.js contains your basic javascript Ajax functions. Is this
right? Also, how could I use Ajax to refresh the table data after a
checkbox is clicked?
~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
-~----------~----~----~----~------~----~------~--~---