Changes between Version 4 and Version 5 of DeveloperGuidelinesS3Framework


Ignore:
Timestamp:
01/15/09 22:19:30 (16 years ago)
Author:
Fran Boon
Comment:

Update to current API

Legend:

Unmodified
Added
Removed
Modified
  • DeveloperGuidelinesS3Framework

    v4 v5  
    2929  return dict(module_name=module_name,modules=modules,options=options)
    3030
     31All tables which are user-editable need to be protected for conflict resolution & synchronization using the predefined fields {{{timestamp}}} & {{{uuidstamp}}}.[[BR]]
     32These are defined in {{{models/__db.py}}}:
     33{{{
     34# Define 'now'
     35# 'modified_on' fields used by T2 to do edit conflict-detection & by DBSync to check which is more recent
     36now=datetime.datetime.today()
     37
     38# Reusable timestamp fields
     39timestamp=SQLTable(None,'timestamp',
     40            SQLField('created_on','datetime',
     41                          writable=False,
     42                          default=request.now),
     43            SQLField('modified_on','datetime',
     44                          writable=False,
     45                          default=request.now,update=request.now))
     46
     47# We need UUIDs as part of database synchronization
     48import uuid
     49uuidstamp=SQLTable(None,'uuidstamp',
     50            SQLField('uuid',length=64,
     51                          writable=False,
     52                          default=uuid.uuid4()))
     53}}}
     54
    3155=== Optional ===
    32 List output can be made more functional by this .represent 'widget':
     56List output are made more functional by this .represent 'widget':
    3357{{{
    3458def shn_list_item(table,resource,action,display='table.name',extra=None):
     
    3963    return DIV(*items)
    4064}}}
    41 You can use it in {{{models/module.py}}} like:
     65This is called in {{{models/__db.py}}} in the RESTlike Controller:
    4266{{{
    43 db.or_organisation.represent=lambda table:shn_list_item(table,resource='organisation',action='display')
    4467db.person.represent=lambda table:shn_list_item(table,resource='person',action='display',display='table.full_name')
    45 db.gis_projection.represent=lambda table:shn_list_item(table,resource='projection',action='display',extra='table.epsg')
    4668}}}
    4769
     
    5274   {{{SQLField('field','text'),}}}
    5375
    54 Form field can be made to use a SELECT dropdown by setting the field as a lookup to another table...linked to the 'uuid' field to allow [wiki:DeveloperGuidelinesDatabaseSynchronization Database Synchronization], but displaying a more user-friendly field (such as 'name'):
     76Form field can be made to use a SELECT dropdown by setting the field as a lookup to another table...linked to the 'id' field to allow [wiki:DeveloperGuidelinesDatabaseSynchronization Database Synchronization], but displaying a more user-friendly field (such as 'name'):
    5577{{{
    56 SQLField('field',length=64),
     78SQLField('field',dn.othertable),
    5779
    58 db.table.field.requires=IS_NULL_OR(IS_IN_DB(db,'othertable.uuid','othertable.name'))
     80db.table.field.requires=IS_NULL_OR(IS_IN_DB(db,'othertable.id','othertable.name'))
    5981}}}
    6082
     
    88110e.g. session.s3.debug & session.s3.self_registration are made available to the default {{{layout.html}}} this way.
    89111
    90 If you wish to clean out all settings to import afresh, then close down Web2Py & start up in shell mode:
    91 {{{
    92 python web2py.py -S sahana -M
    93 }}}
    94 Then run:
    95 {{{
    96 shn_db_clean(db)
    97 }}}
    98 (This function is configured in {{{modules/sahana.py}}})
    99 
     112If you wish to clean out all settings to import afresh, then close down Web2Py & delete all files from {{{/databases}}})
    100113
    101114Modules can set up their own configuration settings tables in a similar way (e.g. GIS does this)
     
    108121We use T2 to handle this for us.
    109122
    110 Add this field to each table which needs protecting (in {{{models/db.py}}}):
     123Add this field to each table which needs protecting (in {{{models/module.py}}}):
    111124{{{
    112 SQLField('modified_on','datetime'), # Used by T2 to do edit conflict-detection
     125timestamp
    113126}}}
    114127