Changes between Version 4 and Version 5 of DeveloperGuidelinesS3Framework
- Timestamp:
- 01/15/09 22:19:30 (16 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
DeveloperGuidelinesS3Framework
v4 v5 29 29 return dict(module_name=module_name,modules=modules,options=options) 30 30 31 All tables which are user-editable need to be protected for conflict resolution & synchronization using the predefined fields {{{timestamp}}} & {{{uuidstamp}}}.[[BR]] 32 These 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 36 now=datetime.datetime.today() 37 38 # Reusable timestamp fields 39 timestamp=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 48 import uuid 49 uuidstamp=SQLTable(None,'uuidstamp', 50 SQLField('uuid',length=64, 51 writable=False, 52 default=uuid.uuid4())) 53 }}} 54 31 55 === Optional === 32 List output can be made more functional by this .represent 'widget':56 List output are made more functional by this .represent 'widget': 33 57 {{{ 34 58 def shn_list_item(table,resource,action,display='table.name',extra=None): … … 39 63 return DIV(*items) 40 64 }}} 41 You can use it in {{{models/module.py}}} like:65 This is called in {{{models/__db.py}}} in the RESTlike Controller: 42 66 {{{ 43 db.or_organisation.represent=lambda table:shn_list_item(table,resource='organisation',action='display')44 67 db.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')46 68 }}} 47 69 … … 52 74 {{{SQLField('field','text'),}}} 53 75 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'):76 Form 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'): 55 77 {{{ 56 SQLField('field', length=64),78 SQLField('field',dn.othertable), 57 79 58 db.table.field.requires=IS_NULL_OR(IS_IN_DB(db,'othertable. uuid','othertable.name'))80 db.table.field.requires=IS_NULL_OR(IS_IN_DB(db,'othertable.id','othertable.name')) 59 81 }}} 60 82 … … 88 110 e.g. session.s3.debug & session.s3.self_registration are made available to the default {{{layout.html}}} this way. 89 111 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 112 If you wish to clean out all settings to import afresh, then close down Web2Py & delete all files from {{{/databases}}}) 100 113 101 114 Modules can set up their own configuration settings tables in a similar way (e.g. GIS does this) … … 108 121 We use T2 to handle this for us. 109 122 110 Add this field to each table which needs protecting (in {{{models/ db.py}}}):123 Add this field to each table which needs protecting (in {{{models/module.py}}}): 111 124 {{{ 112 SQLField('modified_on','datetime'), # Used by T2 to do edit conflict-detection 125 timestamp 113 126 }}} 114 127