Changes between Version 25 and Version 26 of DeveloperGuidelines


Ignore:
Timestamp:
01/01/09 12:19:58 (13 years ago)
Author:
Fran Boon
Comment:

.represent 'widget': shn_list_item()

Legend:

Unmodified
Added
Removed
Modified
  • DeveloperGuidelines

    v25 v26  
    7676  return dict(module_name=module_name,modules=modules,options=options)
    7777
    78 
    79 List output can be made more functional by adding this to your table definitions in models/db.py:
    80    {{{db.table.represent=lambda table: A(table.display_field,_href=t2.action('display_table',table.id))}}}
     78List output can be made more functional by this .represent 'widget':
     79{{{
     80def shn_list_item(table,resource,action,display='table.name',extra=None):
     81    if extra:
     82        items=DIV(TR(TD(A(eval(display),_href=t2.action(resource,[action,table.id]))),TD(eval(extra))))
     83    else:
     84        items=DIV(A(eval(display),_href=t2.action(resource,[action,table.id])))
     85    return DIV(*items)
     86}}}
     87You can use it in {{{models/module.py}}} like:
     88{{{
     89db.or_organisation.represent=lambda table:shn_list_item(table,resource='organisation',action='display')
     90db.person.represent=lambda table:shn_list_item(table,resource='person',action='display',display='table.full_name')
     91db.gis_projection.represent=lambda table:shn_list_item(table,resource='projection',action='display',extra='table.epsg')
     92}}}
    8193
    8294Form labels can be set in a translatable manner using: