How will SQLTABLE help here?

# non-executable pseudo code
result_a = db().select(db.sometable.ALL)
result_b = db().select(db.othertable.ALL)
rows_c = []
for row_a, row_b in zip(result_a.response, result_b.response):
    row_c = (row_b[3], '%.2f' % (row_a[0], ), int(row_b[1]), ...)
    rows_c.append(row_c)
colnames = ('Datetime', 'float', 'n/sec', ...)
# How will I create an SQLTABLE here?

--
Andreas

> Isn't this what SQLTABLE and crud.select is for?
>
> --
> Thadeus
>
> On Sat, Jun 19, 2010 at 8:06 AM, baloan <balo...@googlemail.com> wrote:
> > Since my web application needs to render more than two tables I was
> > too lazy to write/copy/paste table html code over and over again.
> > Instead I implemented render_table which does the job nicely.
> > Everything starts out with one or more database query result sets.
> > Columns are reordered and reassigned to a new target table that shall
> > be rendered.
>
> > Is there a better built-in web2py-ish way to achieve the same?
>
> > Regards, Andreas
> > balo...@gmail.com
>
> > -- views/render_table.html --
> > {{def render_table(table):
> > # render table with header and attributes
> > # string table.colnames[]
> > # string table.colattrs[]
> > # string table.rows[][]
> > }}
> > <table>
> > <thead>
> > {{for cn in table.colnames:}}  <th>{{=cn}}</th>
> > {{pass}}
> > </thead>
> > {{for n, row in enumerate(table.rows):}}
> > <tr{{if n % 2 == 0:}} class='even'{{else:}} class='odd'{{pass}}>
> > {{for cn, col in zip(table.colnames, row):}}
> >    <td{{if cn in table.colattrs:}} {{=table.colattrs[cn]}}
> >    {{elif isinstance(col, float) or isinstance(col, int):}}
> > align='right'
> >    {{pass}}>{{=col}}</td>
> > {{pass}}
> > </tr>
> > {{pass}}
> > </table>{{pass}}
> > -------------

Reply via email to