Changes between Version 1 and Version 2 of DeveloperGuidelines


Ignore:
Timestamp:
12/20/08 03:14:01 (16 years ago)
Author:
Fran Boon
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • DeveloperGuidelines

    v1 v2  
    11Web2Py:
    2 * http://mdp.cti.depaul.edu/examples/static/cookbook.pdf
    3 * http://mdp.cti.depaul.edu/examples/static/web2py_cheatsheet.pdf
     2 - http://mdp.cti.depaul.edu/examples/static/cookbook.pdf
     3 - http://mdp.cti.depaul.edu/examples/static/web2py_cheatsheet.pdf
    44
    55MVC (like Rails)
     
    1111   Python functions in /controllers/module.py
    1212   e.g.
     13{{{
    1314   def list_records():
    1415       list=t2.itemize(table)
    1516       return dict (list=list)
    16    
     17}}}   
    1718  View
    1819   HTML/Javascript templates in /views/module/function.html
     
    2425
    2526Python:
    26 * Slow start
    27  - http://openbookproject.net/thinkcs/python/english2e/
    28 * Quick start
    29  - http://diveintopython.org/
    30 * v.Quick start!
    31     Indentation matters (use 4 spaces instead of Tabs)
    32     OOP - everything is an object
     27 - Slow start
     28  - http://openbookproject.net/thinkcs/python/english2e/
     29 - Quick start
     30  - http://diveintopython.org/
     31 - v.Quick start!
     32  - Indentation matters (use 4 spaces instead of Tabs)
     33  - OOP - everything is an object
    3334
    3435T2 is used for AAA & simplified CRUD (inc Conflict Detection)
     
    3940Create Record:
    4041  Controller
     42{{{
    4143   def add_record():
    4244       form=t2.create(db.table)
    4345       return dict(form=form)
     46}}}
    4447  View
    4548    views/module/add_record.html
     49{{{
    4650     {{=form}}
     51}}}
    4752Display Record:
    4853  Controller
     54{{{
    4955   def display_record():
    5056       item=t2.display(db.table)
    5157       return dict(item=item)
     58}}}
    5259  View
    5360    views/module/display_record.html
     61{{{
    5462     {{=item}}
     63}}}
    5564Update Record:
    5665  Controller
     66{{{
    5767   def display_record():
    5868       form=t2.update(db.table)
    5969       return dict(form=form)
     70}}}
    6071  View
    6172    views/module/add_record.html
     73{{{
    6274     {{=form}}
     75}}}
    6376Delete Record:
    6477  Controller
     78{{{
    6579   def delete_record():
    6680   db(db.table.id==t2.id).delete()
    6781   response.confirmation=T("Record deleted")
    6882   response.view="module/list_records.html"
     83}}}
    6984  View
    7085    normally not used (reuse existing list_records view)
     
    7287
    7388Populate the side navigation Menus by adding this to each controller:
     89{{{
    7490module='module'
    7591# Current Module (for sidebar title)
     
    7995# List Options (from which to build Menu for this Module)
    8096options=db(db['%s_menu_option' % module].enabled=='Yes').select(db['%s_menu_option' % module].ALL,orderby=db['%s_menu_option' % module].priority)
     97}}}
    8198
    8299Each function needs to return these values to the view:
     
    84101
    85102List output can be made more functional by adding this to your table definitions in models/db.py:
    86    db.table.represent=lambda table: A(table.display_field,_href=t2.action('display_table',table.id))
     103   {{{db.table.represent=lambda table: A(table.display_field,_href=t2.action('display_table',table.id))}}}
    87104Form labels can be set in a translatable manner using:
    88    db.table.field.label=T("label")
     105   {{{db.table.field.label=T("label")}}}
    89106Form field can be made to use a TEXTAREA by marking the field as being type 'text':
    90    SQLField('field','text'),
     107   {{{SQLField('field','text'),}}}
    91108Form field can be made to use a SELECT dropdown by setting the field as a lookup to another table:
    92    SQLField('field',db.othertable),
     109   {{{SQLField('field',db.othertable),}}}
    93110Set this to use a different field than 'id' in the views (e.g. 'name') using:
    94    db.table.field.requires=IS_NULL_OR(IS_IN_DB(db,'othertable.id','othertable.name'))
     111   {{{db.table.field.requires=IS_NULL_OR(IS_IN_DB(db,'othertable.id','othertable.name'))}}}
    95112Form field being required can be marked using:
    96    db.table.field.comment=SPAN("*",_class="req")
     113   {{{db.table.field.comment=SPAN("*",_class="req")}}}
    97114Help for a form field can be set using:
    98    A(SPAN("[Help]"),_class="popupLink",_id="tooltip",_title=T("Help|This is what this field is for."))
     115   {{{A(SPAN("[Help]"),_class="popupLink",_id="tooltip",_title=T("Help|This is what this field is for."))}}}
     116
    99117
    100118Conflict Detection:
     
    105123 Controller
    106124  Each controller which incldues protected functions needs this:
     125{{{
    107126   def login():
    108127       response.view='login.html'
     
    115134   @t2.requires_login('login')
    116135   def function():
    117 
     136}}}
    118137
    119138How to add a new module?
     
    122141   Add module to db.module:
    123142    http://127.0.0.1:8000/sahana/appadmin/select/db?query=db.module.id%3E0
    124    Create a table to store the module's menu options to /models/db.py
     143   Create a table to store the module's menu options to /models/module.py
    125144    db.module_menu_option
    126    Add tables to /models/db.py
     145   Add tables to /models/module.py
     146    db.module_table
    127147  Controller
    128148   Add CRUD functions for these tables to /views/module.py
     
    136156
    137157Advanced Tricks:
    138 * Python debugging
    139 - use Web2Py shell: http://www.vimeo.com/879939
    140 - http://docs.python.org/library/doctest.html
    141 - http://docs.python.org/library/bdb.html
    142 * CSS & Javascript debugging
    143 - use Firebug: http://code.google.com/support/bin/answer.py?answer=77412&topic=12044
    144 * jQuery:
    145 - http://www.tvidesign.co.uk/blog/improve-your-jquery-25-excellent-tips.aspx
    146 * Ext:
    147 - http://extjs.com/learn/Tutorial:Introduction_to_Ext_2.0
    148 - http://extjs.com/learn/Manual:Basic_Application_Design
    149 - http://extjs.com/forum/showthread.php?t=26728
    150 - http://extjs.com/learn/Ext_FAQ_Debugging
     158 - Python debugging
     159  - use Web2Py shell: http://www.vimeo.com/879939
     160  - http://docs.python.org/library/doctest.html
     161  - http://docs.python.org/library/bdb.html
     162 - CSS & Javascript debugging
     163  - use Firebug: http://code.google.com/support/bin/answer.py?answer=77412&topic=12044
     164 - jQuery:
     165  - http://www.tvidesign.co.uk/blog/improve-your-jquery-25-excellent-tips.aspx
     166 - Ext:
     167  - http://extjs.com/learn/Tutorial:Introduction_to_Ext_2.0
     168  - http://extjs.com/learn/Manual:Basic_Application_Design
     169  - http://extjs.com/forum/showthread.php?t=26728
     170  - http://extjs.com/learn/Ext_FAQ_Debugging