Complete example extrapolated from my working code (please adapt it to your 
needs) :

#model
db.define_table('t_customer',
    Field('f_vat',
          type='string',
          notnull=True,
          label=T('VAT Nr.'),
          length=32,
          ), 
    Field('f_name',
          type='string',
          notnull=True,
          label=T('Customer Name'),
          length=54,
          ),
    Field('f_approved',
          type='string',
          notnull=True,
          default='pending',
          label=T('Approved'),
          represent=lambda fld, row:(fld=='pending' and \
                                           SPAN(T(fld), _class="yellow")) or 
\
                                    (fld=='yes' and \
                                           SPAN(T(fld), _class="green")) or 
\
                                    (fld=='no' and \
                                           SPAN(T(fld), _class="red")) or 0,
         ),
    Field('active',
          'boolean',
          default=True,
          label=T('Active'),
          writable=False,
          readable=False,
          ),
    Field('created_on',
          'datetime',
          default=request.now,
          label=T('Created On'),
          writable=False,
          readable=False,
          ),
    Field('modified_on',
          'datetime',
          default=request.now,
          label=T('Modified On'),
          writable=False,
          readable=False,
          update=request.now,
          ),
    Field('created_by',
          db.auth_user,
          default=auth.user_id,
          label=T('Created By'),
          writable=False,
          readable=False,
          ),
    Field('modified_by',
          db.auth_user,
          default=auth.user_id,
          label=T('Modified By'),
          writable=False,
          readable=False,
          update=auth.user_id,
          ),
    format='%(f_name)s',
    migrate=settings.migrate
)

# 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)
    return dict(rows=rows, sfields=fields)

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

{{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 sfields[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%;')}}
{{pass}}
{{pass}}
{{=SQLTABLE(rows, headers=headers)}}
{{else:}}
{{=P('no data to show')}}
{{pass}}




Il giorno domenica 4 novembre 2012 15:11:12 UTC+1, Simon Ashley ha scritto:
>
> Thanks.
> Will give that another look. 
> Have tried this approach (many attempts) but could not generate the 
> correct HTML.
>
> (will play around with the class as the default seems to translate the 
> =IMG element as text/string)
> If you have a snippet of a working example, would appreciate it.
>
>
>

-- 



Reply via email to