88 | | == Tutorial == |
89 | | |
90 | | This tutorial was given at !SahanaCamp 1.1 in Taiwan: |
91 | | * http://www.slideshare.net/AidIQ/sahana-introduction-to-the-code-v2 |
92 | | * [wiki:DeveloperQuickstart] |
93 | | |
94 | | === Model === |
95 | | Defines databases in: {{{/models/module.py}}} |
96 | | |
97 | | The Models are loaded 1st within Web2Py processing, before the controllers.[[BR]] |
98 | | So you can import any global modules/set any global variables here.[[BR]] |
99 | | The Models are imported in alphabetical order, so we load the files which other modules depend on 1st, hence naming them appropriately:[[BR]]{{{000_config.py}}}, {{{01_crud.py}}}, {{{02_pr.py}}}, {{{03_gis.py}}}, etc |
100 | | |
101 | | === Controller === |
102 | | Python functions in {{{/controllers/module.py}}} [[BR]] |
103 | | e.g. |
104 | | {{{ |
105 | | def list_records(): |
106 | | items = crud.select(table) |
107 | | return dict(items=items) |
108 | | }}} |
109 | | |
110 | | === View === |
111 | | HTML/Javascript templates in {{{/views/module/function.html}}} |
112 | | * these are normal HTML/JS files with the ability to add in Python code (e.g. variables) surrounded by brackets: {{ interpreted python here }} |
113 | | * there should be an .html file available for each function in the module (name normally being the same as the function) |
114 | | * these normally inherit from {{{views/layout.html}}} which also includes the !JavaScript from {{{views/*_ajax.html}}} |
115 | | * 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 |
116 | | |
117 | | Static CSS/Javascript files are stored in {{{/static}}} |
118 | | |