Not necessarily.
You may return in the view only the table with new headers.

Following code is not tested, so please check for errors.

# controller
@auth.requires_login()
def customer_select():
    f,v = request.args(0), request.args(1)
    try: query = f and db.t_customer[f] == v or db.t_customer
    except: redirect(URL('default', 'error'))
    fields=['id','f_vat','f_name','f_approved']
    selection = [db.t_customer[field] for field in fields]
    rows = db(query)(db.t_customer.active==True).select(*selection)
    table = build_table(rows, fields)
    return dict(table=table)


def build_table(rows, fields):
    rows = rows
    fields = fields
    if rows:
        headers = dict((str(h), h.label) for h in db.t_customer)
        for header in headers:
            h_field = header.split('.')[1]
            if h_field in fields[1:]:
                headers[header] = SPAN(IMG(
                                       _src=URL('static/images/header_icons'
,
                                                h_field+'.png'),
                                       _alt=str(db.t_customer[h_field].label
),
                                       _width='16',
                                       _height='16'),
                                   _style='width:100%;')
        table = SQLTABLE(rows, headers=headers)
    else:
        table = P('no data to show')
    return table


# view
{{extend 'layout.html'}}

{{=table}}




Il giorno domenica 4 novembre 2012 21:39:27 UTC+1, Simon Ashley ha scritto:
>
> ahaa, thanks Paulo, that make sense i.e. to do it all in the view
>>
>>

-- 



Reply via email to