Version 104 (modified by 14 years ago) ( diff ) | ,
---|
Table of Contents
Developer Guide
Install a Development Environment
Python
Indentation matters (use 4 spaces instead of Tabs)
- http://diveintopython.org/
- http://openbookproject.net/thinkcs/python/english2e/
- Style Guide: http://www.python.org/dev/peps/pep-0008/
- lxml (XML I/O): http://codespeak.net/lxml/tutorial.html
More details at: DeveloperGuidelinesCodeConventions
Web2Py
This is an MVC environment (like Rails & Django. Django polls turorial conversion course).
Web2Py can work at several different levels of abstraction.
The Sahana Eden framework (S3) is built on Web2Py's Auth/Crud classes in tools.py
(with some remnants of the older T2), however sometimes we need more control therefore need to drop down a level or two.
- http://web2py.com/examples/default/docs (recommend the 'New Cookbook' as well as the official Manual v2)
Recommend using the CLI to try out code snippets in the Web2Py environment (gluon, Model):
python web2py.py -S eden -M
Web2Py can be extended through Plugins & also has a recipes site.
Model
Defines databases in: /models/module.py
The Models are loaded 1st within Web2Py processing, before the controllers.
So you can import any global modules/set any global variables here.
The Models are imported in alphabetical order, so we load the files which other modules depend on 1st, hence naming them appropriately:000_config.py
, 01_crud.py
, 02_pr.py
, 03_gis.py
, etc
Controller
Python functions in /controllers/module.py
e.g.
def list_records(): items=t2.itemize(table) return dict(items=items)
View
HTML/Javascript templates in /views/module/function.html
- these are normal HTML/JS files with the ability to add in Python code (e.g. variables) surrounded by brackets: {{ interpreted python here }}
- there should be an .html file available for each function in the module (name normally being the same as the function)
- these normally inherit from
views/layout.html
which also includes the JavaScript fromviews/*_ajax.html
- 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
Static CSS/Javascript files are stored in /static
Javascript
- jQuery is used for client-side business logic (hiding fields, opening up tabs, etc):
- Tutorial 1: http://docs.jquery.com/Tutorials:How_jQuery_Works
- Tutorial 2: http://docs.jquery.com/Tutorials:Getting_Started_with_jQuery
- Main reference: http://docs.jquery.com
- We use some plugins: http://plugins.jquery.com
- & some Widgets: http://jqueryui.com
- ExtJS is used for some advanced widgets:
- W3Schools' basic JS: http://www.w3schools.com/js/
Reserved Keywords
- 'request' -> web2py internal use
- 'key' as a db row name -> MySQL confuses it with internal keyword KEY
- http://dev.mysql.com/doc/mysqld-version-reference/en/mysqld-version-reference-reservedwords-5-0.html
- http://www.postgresql.org/docs/8.1/static/sql-keywords-appendix.html
PEP8
- Please ensure PEP8 compliance for all code you propose for a merge into the Trunk.
- Use static/scripts/tools/pep8.py to check for pep8 compliance.
Execute the following in your eden directory
python static/scripts/tools/pep8.py yourfile.py
Developer Guidelines
- WSGI likes print statements to go to
sys.stderr
notsys.stdout
: http://code.google.com/p/modwsgi/wiki/DebuggingTechniques
- Sahana Eden Framework: S3
- Internationalisation
- Help for Developers Migrating from Sahana PHP
- Help for Developers Migrating from Django
- How to add a new Module?
- Usability
- Testing
- TestCases - User Testing - List of things to test
- Optimisation
- Release Process
- Tips - useful links to explore
- TroubleShooting