S3 is a codename for Sahana Eden Server & Client can be on the same machine Each part needs to be debugged separately: Eclipse works well for the Server-side Python, whilst Firebug is excellent for the generated HTML/CSS/JavaScript JavaScript libraries we use include jQuery & ExtJS
There are notes on the Wiki for installing a developer environment on Windows, Mac or Linux machines if you wish to run in other environments later.
Look around the filesystem in web2py/applications/eden folder Similar layout structure to other MVC frameworks, such as Ruby-on-Rails & Django
JavaScript which doesn’t require server-side parsing put into static Python Libraries available: System Python, Web2Py, Eden (S3*)
The problems faced by both the victims of and responders to disasters are numerous. Beyond the trauma, this involves having to coordinate, manage and track things. In countries at risk of being affected by large scale sudden onset disasters, these problems can be massive and overwhelming.
Normally you work in a local branch on your PC. You Merge changes in regularly from Trunk. You Push your changes to your branch on LaunchPad (You Pull from LaunchPad to update your server sites)
Minimise the time taken to process Manage dependencies No need to import most of the libraries in ‘gluon/’
Create a new file in the models folder called inc.py & type in the text above – be careful to use the correct case for Field!
Create a new file in the controllers folder called inc.py & type in the text above – be careful to get the indentation correct!
Note that you’ll need to Register yourself as a user on the system before you’re allowed to create a resource. The 1 st user to register gets the Administrator role by default.
Create a new folder in the views folder called ‘ inc ’ & inside that put a new file ‘ incident_list_create.html’ . Type in the text above. Refresh the incident page to see the new text: http://127.0.0.1:8000/eden/inc/ incident No need to learn another macro language Defaults (non-REST) to views/controller/function.html Open the About page ( http://127.0.0.1:8000/eden/default/about ) & browse the variables We store our S3 variables in response.s3.*, session.s3.* so as not to pollute the Web2Py namespace
unique=True is a SQL-level constraint. Open your inc.py from the models directory & add the extra code above. Validators are DAL-level constraints which produce nice error messages instead of tickets! Validators provide server-side validation & some also provide client-side rendering & validation Web2Py automatically adds a Validator when the SQL constraint is set.
Fields default to type ‘string’. ‘ date’ is the SQL-level field type & also provides the class in the HTML which means we get a date widget Add the extra code above to your file & refresh the page, now enter a date.
Add the extra code above to your file & refresh the page to see the default value
Add this to your model (underneath the table definition) & try it out
You can check out the languages file, if you wish: http://127.0.0.1:8000/admin/default/design/eden#languages Update all languages
Add this to your model (underneath the table definition) & try it out Comment is rendered as ‘column3’ (although can be moved using ‘formstyle’) We also use the same space for Help buttons & ‘Add New Resource’ links. NB For optimal performance, we normally add such comments in the Controller instead & put them inside a ‘prep’ to tale effect just when ‘r.representation in shn_interactive_view_formats’
Add this to your model (underneath the table definition) & try it out Comment is rendered as ‘column3’ (although can be moved using ‘formstyle’) We also use the same space for Help buttons & ‘Add New Resource’ links. NB For optimal performance, we normally add such comments in the Controller instead & put them inside a ‘prep’ to tale effect just when ‘r.representation in shn_interactive_view_formats’
Add this to your model (underneath the table definition) & try it out Comment is rendered as ‘column3’ (although can be moved using ‘formstyle’) We also use the same space for Help buttons & ‘Add New Resource’ links. NB For optimal performance, we normally add such comments in the Controller instead & put them inside a ‘prep’ to tale effect just when ‘r.representation in shn_interactive_view_formats’
This should be available as a script or an alias ‘w2p’ iPython needs to be installed for object exploring.
Add this text to the file 000_config.py in the models folder. Navigate to the home page to see the module appear both there & on the menu. Try navigating to the module. Module Type 10 means appears in the ‘more’ section of the default modules menu. (Most deployments will create a fully-customised menu anyway)
Add this text to your controller file & now open the module. “ Custom View” is a Doc String One should be added to all functions for automatic documentation generators & interactive browsing of docs You can try this out in the Interactive Shell: w2p execfile("applications/eden/controllers/vts.py", globals()) help(index)
Create a file called ‘index.html’ inside the views/inc folder See plain HTML being interspersed with the server-side parsed Python Look at another module’s index.html What’s bad about this index?
Add this text to your controller (outside the functions – e.g. at the top) & see what effect this has on your module.
Copt this text into your model. Note the use of string substitution to define the tablename
Tells SQL that these fields are ‘reference’ fields (i.e. Foreign Keys) - They store integers which are a pointer to the ID field in the other tables.
Copy this text into your Model & refresh the presence page Reusable field defined in models/03_gis.py Includes additional useful configuration such as .requires & .represent
Copt this text into your controller. Try it out. Note the automation of the resource name to minimise the editing after copy/paste of new functions
Copy this text into your model & see what it does for the page IS_ONE_OF() will provide us a dropdown showing license plates, even though we actually store the ID. This is an S3 validator which extends Web2Py’s IS_IN_DB() to support the ‘deleted’ status & also allow the use of lambdas as formatting options.
We can add additional fields into the link table.
IS_ONE_OF provides the representation in the dropdown table.field.represent provides the representation in Display/List views A lambda is a Python feature for defining anonymous functions on the fly: http://diveintopython.org/power_of_introspection/lambda_functions.html
Optimise the query – we know we only want a single record & a single field from that record
Add the optimised query to your model.
Add this to your model underneath the definition of the Presence table & try out the URL. No need for dedicated presence() controller
Add this Resource Header definition to your Controller. Be careful to get the end brackets & commas right! ‘ r’ is the resource
Then plug it into the Controller
Take a look at the HTML structure of the page in Firebug.
Web2Py source code very accessible – small enough to be able to grasp the whole thing after not too long FORM defined in gluon/html.py: Dumb HTML elements SQLFORM defined in gluon/sqlhtml.py: Self-processing forms which update the database CRUD defined in gluon/tools.py: Wrappers around SQLFORM - We actually change CRUD a lot & are looking to remove it completely – building straight on top of SQLFORM() REST defined in modules/s3xrc.py: RESTful interface & XML representations If you drop down a level, then need to do things more manually & need to take care of framework issues yourself.
Whilst we spend a lot of time updating developer documentation, the actual codebase always moves faster, so the source is always the most authoritative source of information.