Version 13 (modified by 11 years ago) ( diff ) | ,
---|
Developer Guidelines - Basics
Table of Contents
Here are some helpful hints to get started developing in Sahana Eden.
Running Sahana Eden
cd .. # the web2py main directory python web2py.py
Or if you don't want to have to enter a password (or have issues launching the Web2Py GUI).
python web2py.py -a 1234
Wiping the Database
Out of the box Sahana Eden is set to use the SQLite database. If you want to wipe all the data, simply delete the databases/
directory, along with the sessions/
directory (this contains details about your login - which will be invalid as you'll be deleting the user account). The next time you run Sahana Eden, it will recreate the database tables.
Pre-Populating Data
Sahana Eden is able to "Pre-Populate" data so you can explore/test/develop the application with different types of data. Pre-Populate options are associated with the Templates, but they can be set in models/000_config.py
.
IFRC_Train
is a good set of pre-populate to use (See: https://github.com/flavour/eden/tree/master/private/templates/IFRC_Train). It also has an admin user account: admin@example.com password: testing. To use it edit models/000_config.py
:
After:
# ============================================================================= # Over-rides to the Template may be done here
Add (or un-comment):
settings.base.prepopulate = ["IFRC_Train"]
Pre-populate data will only be created if the database is empty, so you may need to wipe the database first. It may take a few minutes to load the data.
Debug Mode
In models/000_config.py
uncomment this line:
settings.base.debug = True
to:
- Use the non-minified CSS & JS
- See changes in
modules/s3db
files without restarting Web2Py
Running a Sahana Eden Python Shell
To open a Python Shell in the Sahana Eden Environment, where you can inspect Web2Py and Sahana Eden variables as well as access the data:
cd web2py python web2py.py -S eden -M
To have database changes be persistent (e.g. to see via Web UI), you will need to commit the transactions: db.commit()
.
Python
Indentation matters (use 4 spaces instead of Tabs)
- http://diveintopython.net
- http://openbookproject.net/thinkcs/python/english2e/
- http://software-carpentry.org
- Python v2 documentation: http://docs.python.org/ (We are currently using v2.7.)
Web2Py
This is an MVC environment (like Rails & Django. Django polls tutorial 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.
Can execute a controller to be able to access its functions using:
execfile("applications/eden/controllers/mycontroller.py", globals())
Web2Py can be extended through Plugins & also has a recipes site.
Javascript
- W3Schools' basic JS: http://www.w3schools.com/js/
- 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:
- S3 includes a cross-browser debug utility (only shows up when ?debug=1):
s3_debug('message', value);
All global variables should be in the S3 namespace:
Private variables should be protected, e.g. using the Module Pattern:
- http://yuiblog.com/blog/2007/06/12/module-pattern/
- http://www.adequatelygood.com/2010/3/JavaScript-Module-Pattern-In-Depth
Can test out the performance of different options to achieve a task using:
Can check quality using JSLint:
XSLT
To transform XML (and CSV) files for importing and exporting data.