Changes between Version 7 and Version 8 of DeveloperGuidelines
- Timestamp:
- 12/20/08 05:04:23 (16 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
DeveloperGuidelines
v7 v8 1 == Python == 2 - Slow start 3 - http://openbookproject.net/thinkcs/python/english2e/ 4 - Quick start 5 - http://diveintopython.org/ 6 - v.Quick start! 7 - Indentation matters (use 4 spaces instead of Tabs) 8 - OOP - everything is an object 9 1 10 == Web2Py == 2 11 * http://mdp.cti.depaul.edu/examples/static/cookbook.pdf … … 8 17 Defines databases in: {{{/models/module.py}}} (equivalent of inst/mysql-dbcreate.sql) 9 18 19 The Models are loaded 1st within Web2Py processing, before the controllers. 20 So you can import any global modules/set any global variables here. 21 The Models are imported in alphabetical order, so we load the files which other modules depend on 1st, hence naming them {{{_db.py}}}, {{{_gis.py}}} 22 10 23 === Controller === 11 Python functions in /controllers/module.py24 Python functions in {{{/controllers/module.py}}} 12 25 e.g. 13 26 {{{ … … 18 31 19 32 === View === 20 HTML/Javascript templates in /views/module/function.html33 HTML/Javascript templates in {{{/views/module/function.html}}} 21 34 - these are normal HTML/JS files with the ability to add in Python code (e.g. variables) surrounded by brackets: {{ interpreted python here }} 22 35 - there should be an .html file available for each function in the module (name normally being the same as the function) 36 - these normally inherit from {{{views/layout.html}}} which also includes the Javascript from {{{views/web2py_ajax_t2.html}}} 23 37 - if there is no view defined then a default view will be displayed, which will show the values of all the data it can see, but not be formatted nicely 24 38 25 CSS/Javascript files are stored in /static (equivalent of www/res)39 CSS/Javascript files are stored in {{{/static}}} (equivalent of {{{www/res}}}) 26 40 27 Python:28 - Slow start29 - http://openbookproject.net/thinkcs/python/english2e/30 - Quick start31 - http://diveintopython.org/32 - v.Quick start!33 - Indentation matters (use 4 spaces instead of Tabs)34 - OOP - everything is an object35 41 36 T2 is used for AAA & simplified CRUD (inc Conflict Detection) 37 http://mdp.cti.depaul.edu/examples/static/t2.pdf 38 We extend the T2 class in modules/sahana.py 42 == T2 == 43 This plugin is used for AAA & simplified CRUD (inc Conflict Detection) 44 * http://mdp.cti.depaul.edu/examples/static/t2.pdf 45 We extend the T2 class in {{{modules/sahana.py}}} 39 46 40 47 DeveloperGuidelinesCreateReadUpdateDelete … … 56 63 List output can be made more functional by adding this to your table definitions in models/db.py: 57 64 {{{db.table.represent=lambda table: A(table.display_field,_href=t2.action('display_table',table.id))}}} 65 58 66 Form labels can be set in a translatable manner using: 59 67 {{{db.table.field.label=T("label")}}} 68 60 69 Form field can be made to use a TEXTAREA by marking the field as being type 'text': 61 70 {{{SQLField('field','text'),}}} 71 62 72 Form field can be made to use a SELECT dropdown by setting the field as a lookup to another table: 63 73 {{{SQLField('field',db.othertable),}}} 74 64 75 Set this to use a different field than 'id' in the views (e.g. 'name') using: 65 76 {{{db.table.field.requires=IS_NULL_OR(IS_IN_DB(db,'othertable.id','othertable.name'))}}} 77 66 78 Form field being required can be marked using: 67 79 {{{db.table.field.comment=SPAN("*",_class="req")}}} 80 68 81 Help for a form field can be set using: 69 82 {{{A(SPAN("[Help]"),_class="popupLink",_id="tooltip",_title=T("Help|This is what this field is for."))}}} 70 83 71 84 72 Conflict Detection: 73 Add this field to each table which needs protecting (in models/db.py): 85 === Conflict Detection === 86 Add this field to each table which needs protecting (in {{{models/db.py}}}): 87 {{{ 74 88 SQLField('modified_on','datetime'), # Used by T2 to do edit conflict-detection 89 }}} 75 90 76 How to add a new module? 77 - copy existing & edit! 78 Model 79 Add module to db.module: 80 http://127.0.0.1:8000/sahana/appadmin/select/db?query=db.module.id%3E0 81 Create a table to store the module's menu options to /models/module.py 82 db.module_menu_option 83 Add tables to /models/module.py 84 db.module_table 85 Controller 86 Add CRUD functions for these tables to /views/module.py 87 View 88 Add HTML templates for these functions: /views/module/function.html 91 DeveloperGuidelinesNewModule 89 92 90 How to do Options fields? 93 === Options fields === 91 94 Sahana2 has a generic 'field_options' table for storing Options fields/. 92 95 Sahana3 uses a separate table for each lookup list