|Version 13 (modified by 14 years ago) ( diff ),|
We have built an S3 framework as a higher level of abstraction on top of T2 (now Auth/Crud).
This should be used by modules where possible, but if more power is needed then drop down a level of two (to T2, to base Web2Py or to raw Python).
T2 is used for:
- simplified CRUD
- Conflict Detection
Auth is used for:
NB Auth & Crud are being moved from T2 into Web2Py's
gluon/tools.py with an improved API, so we should follow this (once in Web2Py API will always be backwards-compatible unlike T2):
We extend the Auth/Crud/T2 classes in
Patches to the framework should be done here.
If they're generic enough then they can be suggested to Massimo for moving upstream to either Web2Py or T2.
We extend the CRUD with a RESTlike controller.
This provides details on how to configure your Model & Controllers. Views may not be required, other than index.html
Each Controller should start like this (to populate the side navigation Menus):
module='module' # Current Module (for sidebar title) module_name=db(db.module.name==module).select().name_nice # List Modules (from which to build Menu of Modules) modules=db(db.module.enabled=='Yes').select(db.module.ALL,orderby=db.module.menu_priority) # List Options (from which to build Menu for this Module) options=db(db['%s_menu_option' % module].enabled=='Yes').select(db['%s_menu_option' % module].ALL,orderby=db['%s_menu_option' % module].priority)
Each function needs to return these values to the view:
All tables which are user-editable need to be protected for conflict resolution & synchronization using the predefined fields
These are defined in
# Define 'now' # 'modified_on' fields used by T2 to do edit conflict-detection & by DBSync to check which is more recent now=datetime.datetime.today() # Reusable timestamp fields timestamp=SQLTable(None,'timestamp', SQLField('created_on','datetime', writable=False, default=request.now), SQLField('modified_on','datetime', writable=False, default=request.now,update=request.now)) # We need UUIDs as part of database synchronization import uuid uuidstamp=SQLTable(None,'uuidstamp', SQLField('uuid',length=64, writable=False, default=uuid.uuid4()))
List output are made more functional by this .represent 'widget':
def shn_list_item(table,resource,action,display='table.name',extra=None): if extra: items=DIV(TR(TD(A(eval(display),_href=t2.action(resource,[action,table.id]))),TD(eval(extra)))) else: items=DIV(A(eval(display),_href=t2.action(resource,[action,table.id]))) return DIV(*items)
This is called in
models/__db.py in the RESTlike Controller:
Form labels can be set in a translatable manner using:
Form field can be made to use a TEXTAREA by marking the field as being type 'text':
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 Database Synchronization, but displaying a more user-friendly field (such as 'name'):
Form field being required can be marked using:
Help for a form field can be set using:
A(SPAN("[Help]"),_class="tooltip",_title=T("Help Title|This is what this <a href='http://wikipedia.org/Field' target=_blank>field</a> is for."))
Different Flash styles can be set via:
session.error=T("Unsupported format!") redirect(URL(r=request,f=resource))
or (in a Multiple Table form.accepts):
Supported styles are:
- .confirmation (Standard T2 Flash messages are usually of this sort so we class them in the same way)
System-wide settings have their default values set in
Upon 1st run of the system, these settings are loaded into the database from where they can subsequently be edited to configure the running instance.
If these settings are required by all Views then can patch the session to see them in
e.g. session.s3.debug & session.s3.self_registration are made available to the default
layout.html this way.
If you wish to clean out all settings to import afresh, then close down Web2Py & delete all files from
Modules can set up their own configuration settings tables in a similar way (e.g. GIS does this)
Sahana is a multi-user system so there is a potential for multiple users to be editing the same record at once.
We use T2 to handle this for us.
Add this field to each table which needs protecting (in
This field is also used in Database Synchronization