Advertisement

GHC

AidIQ
AidIQ
Sep. 15, 2010
Advertisement

More Related Content

Advertisement

GHC

  1. Sahana Eden: Emergency Development Environment 15 September 2010, Grace Hopper Celebration Fran Boon [email_address]
  2. eden module resource
  3. Sahana Eden: Session 2 15 September 2010, Grace Hopper Celebration Fran Boon [email_address]
  4. Branches LaunchPad Merge proposal Trunk Local Branch Your Branch bzr merge bzr push
  5. URL(a= application , c= controller , f= function , args=[], vars={})
  6. RHeader Tabs
  7. End
  8. S3 is built on Web2Py REST CRUD SQLFORM FORM

Editor's Notes

  1. 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
  2. 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.
  3. Look around the filesystem in web2py/applications/eden folder Similar layout structure to other MVC frameworks, such as Ruby-on-Rails & Django
  4. JavaScript which doesn’t require server-side parsing put into static Python Libraries available: System Python, Web2Py, Eden (S3*)
  5. For each of these, you should find at least 1 Model, a single Controller & a folder containing 1 or more Views
  6. Minimise the time taken to process Manage dependencies No need to import most of the libraries in ‘gluon/’
  7. Sahana Eden is a Resource-centric application: Persons, Locations, etc
  8. Create a new file in the Models folder called ‘vts.py’ & type in the text above. Remember that whitespace matters! # Text after this symbol is a comment & is ignored If you make a mistake, then the Ticketing system should catch the error & let you know what you did wrong.
  9. No need to create a manual routes entry, unlike other frameworks, like Django
  10. Create a new file in the Controllers folder called ‘vts.py’ & type in the text above.
  11. 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.
  12. Web Services, Mash-ups
  13. Minimise the time taken to process Manage dependencies No need to import most of the libraries in ‘gluon/’
  14. Deleted Columns / Tables simply Ignored
  15. Take a look at them now Remember that execution order is defined by alphabetical order
  16. Take a look at them now
  17. Take a look at them now
  18. These defaults are why we didn’t need any views for our application.
  19. No need to learn another macro language Can Extend just a single other file Can Include many others
  20. Create a new folder in the views folder called ‘vts’ & inside that put a new file ‘vehicle_list_create.html’. Type in the text above. Refresh the vehicle page to see the new text: http://127.0.0.1:8000/eden/vts/vehicle
  21. Open the About page & browse the variables We store our S3 variables in response.s3.*, session.s3.* so as not to pollute the Web2Py namespace
  22. unique=True is a SQL-level constraint. Open your vts.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.
  23. 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.
  24. Add the extra code above to your file & refresh the page to see the default value
  25. Add this to your model (underneath the table definition) & try it out
  26. You can check out the languages file, if you wish: http://127.0.0.1:8000/admin/default/design/eden#languages Update all languages
  27. 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’
  28. Try them out…copy/paste from another controller & then edit…see what effect this has on your module.
  29. This should be available as a script or an alias ‘w2p’ iPython needs to be installed for object exploring.
  30. 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)
  31. URL() is an example of an HTML ‘Helper’ object Remember that after server-side Python finishes, we still have a lot of possibilities client-side with JavaScript.
  32. 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)
  33. 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)
  34. Create a file called ‘index.html’ inside the views/vts 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?
  35. Add this text to your controller (outside the functions – e.g. at the top) & see what effect this has on your module.
  36. Google: web2py dal Try these out in the Web2Py shell  Don’t take effect until you db.commit() Beware locking with Sqlite! (e.g. cron tasks) Wipe DB if developing a lot For Production, split Dev/UAT/Prod instances so that you can plan Data Migrations (Live migrations works in most cases, but some do need manual scripts still – not a complete ‘Get out of jail free’).
  37. Don’t take effect until you db.commit()
  38. Copt this text into your model. Note the use of string substitution to define the tablename
  39. 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.
  40. 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
  41. 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
  42. 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.
  43. We can add additional fields into the link table.
  44. 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
  45. Optimise the query – we know we only want a single record & a single field from that record
  46. Add the optimised query to your model.
  47. Add this to your model underneath the definition of the Presence table & try out the URL. No need for dedicated presence() controller
  48. Add this Resource Header definition to your Controller. Be careful to get the end brackets & commas right! ‘ r’ is the resource
  49. Then plug it into the Controller
  50. Take a look at the HTML structure of the page in Firebug.
  51. 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.
  52. 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.
Advertisement