Changes between Version 7 and Version 8 of DeveloperGuidelines


Ignore:
Timestamp:
12/20/08 05:04:23 (14 years ago)
Author:
Fran Boon
Comment:

--

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
    110== Web2Py ==
    211 * http://mdp.cti.depaul.edu/examples/static/cookbook.pdf
     
    817Defines databases in: {{{/models/module.py}}}   (equivalent of inst/mysql-dbcreate.sql)
    918
     19The Models are loaded 1st within Web2Py processing, before the controllers.
     20So you can import any global modules/set any global variables here.
     21The 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
    1023=== Controller ===
    11 Python functions in /controllers/module.py
     24Python functions in {{{/controllers/module.py}}}
    1225e.g.
    1326{{{
     
    1831
    1932=== View ===
    20 HTML/Javascript templates in /views/module/function.html
     33HTML/Javascript templates in {{{/views/module/function.html}}}
    2134   - these are normal HTML/JS files with the ability to add in Python code (e.g. variables) surrounded by brackets: {{ interpreted python here }}
    2235   - 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}}}
    2337   - 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
    2438
    25    CSS/Javascript files are stored in /static      (equivalent of www/res)
     39   CSS/Javascript files are stored in {{{/static}}}      (equivalent of {{{www/res}}})
    2640
    27 Python:
    28  -  Slow start
    29   - http://openbookproject.net/thinkcs/python/english2e/
    30  - Quick start
    31   - http://diveintopython.org/
    32  - v.Quick start!
    33   - Indentation matters (use 4 spaces instead of Tabs)
    34   - OOP - everything is an object
    3541
    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 ==
     43This plugin is used for AAA & simplified CRUD (inc Conflict Detection)
     44 * http://mdp.cti.depaul.edu/examples/static/t2.pdf
     45We extend the T2 class in {{{modules/sahana.py}}}
    3946
    4047DeveloperGuidelinesCreateReadUpdateDelete
     
    5663List output can be made more functional by adding this to your table definitions in models/db.py:
    5764   {{{db.table.represent=lambda table: A(table.display_field,_href=t2.action('display_table',table.id))}}}
     65
    5866Form labels can be set in a translatable manner using:
    5967   {{{db.table.field.label=T("label")}}}
     68
    6069Form field can be made to use a TEXTAREA by marking the field as being type 'text':
    6170   {{{SQLField('field','text'),}}}
     71
    6272Form field can be made to use a SELECT dropdown by setting the field as a lookup to another table:
    6373   {{{SQLField('field',db.othertable),}}}
     74
    6475Set this to use a different field than 'id' in the views (e.g. 'name') using:
    6576   {{{db.table.field.requires=IS_NULL_OR(IS_IN_DB(db,'othertable.id','othertable.name'))}}}
     77
    6678Form field being required can be marked using:
    6779   {{{db.table.field.comment=SPAN("*",_class="req")}}}
     80
    6881Help for a form field can be set using:
    6982   {{{A(SPAN("[Help]"),_class="popupLink",_id="tooltip",_title=T("Help|This is what this field is for."))}}}
    7083
    7184
    72 Conflict Detection:
    73 Add this field to each table which needs protecting (in models/db.py):
     85=== Conflict Detection ===
     86Add this field to each table which needs protecting (in {{{models/db.py}}}):
     87{{{
    7488SQLField('modified_on','datetime'), # Used by T2 to do edit conflict-detection
     89}}}
    7590
    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
     91DeveloperGuidelinesNewModule
    8992
    90 How to do Options fields?
     93=== Options fields ===
    9194Sahana2 has a generic 'field_options' table for storing Options fields/.
    9295Sahana3 uses a separate table for each lookup list