SahanaCamp NYC Day 3: Eden Technical Workshop

1,713 views

Published on

SahanaCamp NYC Day 3 - Eden Technical Workshop

Published in: Technology, Business
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,713
On SlideShare
0
From Embeds
0
Number of Embeds
588
Actions
Shares
0
Downloads
17
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

SahanaCamp NYC Day 3: Eden Technical Workshop

  1. 1. Sahana EdenTechnical Workshop Fran Boon fran@sahanafoundation.org SahanaCamp NYC 1
  2. 2. AgendaThursday 10:30 Installing a Developer Environment 11:30 Building your own Applications 12:00 Lunch 13:00 Building your own Applications 13:30 Resources 14:00 Building your own Applications 14:30 Modifying existing Applications 15:45 Git and GitHub 16:25 Plan Breakout Sessions 17:00 Adjourn SahanaCamp NYC 2
  3. 3. AgendaFriday 09:00 Breakout Sessions 10:45 Code Sprint: Your Projects 12:00 Working Lunch 13:00 Next Steps 13:30 Community Resources 14:00 Adjourn SahanaCamp NYC 3
  4. 4. Building your own Applications Fran Boon fran@sahanafoundation.org SahanaCamp NYC 4
  5. 5. Whitespace MattersUnlike other languages which use parentheses todelimit code blocks {...}, Python instead uses WhiteSpace SahanaCamp NYC 5
  6. 6. Debug Modemodels/000_config.pydeployment_settings.base.debug = True  Reloads modules/eden every request  CSS & JavaScript unminified SahanaCamp NYC 6
  7. 7. Training ModuleResource: Course Name Date / Time Location: Venue Facilitator Welcome Pack SahanaCamp NYC 7
  8. 8. Define the Basic Data Modelmodels/training.pytablename = "training_course"db.define_table(tablename, Field("name"), Field("start"), Field("facilitator"), ) Table Name: module_resource Database migrated automatically SahanaCamp NYC 8
  9. 9. Add a Controllercontrollers/training.pydef course(): return s3_rest_controller() Functions map URLs to code & resources SahanaCamp NYC 9
  10. 10. Try it out!http://127.0.0.1:8000/eden/training/course List Create Read Update Delete SahanaCamp NYC 10
  11. 11. Other Formatshttp://127.0.0.1:8000/eden/training/course .xlshttp://127.0.0.1:8000/eden/training/course .xmlhttp://127.0.0.1:8000/eden/training/course .json SahanaCamp NYC 11
  12. 12. Pivot Table Reportshttp://127.0.0.1:8000/eden/training/course /report SahanaCamp NYC 12
  13. 13. Field Typesmodels/training.py Field("start", "datetime"), Field("welcome_pack", "upload"), SahanaCamp NYC 13
  14. 14. Field Labelsmodels/training.py Field("start", "datetime", label=T("Start Date")), SahanaCamp NYC 14
  15. 15. Links to other Resourcesmodels/training.pytablename = "training_course"db.define_table(tablename, Field("name"), Field("start", "datetime", label = "Start Date"), s3db.pr_person_id(label="Facilitator"), Field("welcome_pack", "upload"), ) SahanaCamp NYC 15
  16. 16. Links to other Resourcesmodels/training.pytablename = "training_course"db.define_table(tablename, Field("name"), Field("start", "datetime", label = "Start Date"), s3db.pr_person_id(label="Facilitator"), s3db.super_link("site_id","org_site"), Field("welcome_pack", "upload"), ) SahanaCamp NYC 16
  17. 17. Links to other Resourcesmodels/training.pys3db.super_link("site_id", "org_site", label = "Venue", readable = True, writable = True, represent = s3db.org_site_represent, ), SahanaCamp NYC 17
  18. 18. Menus: Top levelmodels/000_config.pydeployment_settings.modules = OrderedDict([ ("training", Storage( name_nice = "Training", module_type = 1, )), SahanaCamp NYC 18
  19. 19. Menus: 2nd levelmodules/eden/menus.pyclass S3OptionsMenu: def training(self): return M(c="training")( M("Courses", f="course")( M("New", m="create"), M("List All"), M("Report", m="report"), ) ) SahanaCamp NYC 19
  20. 20. Module Index Pagehttp://127.0.0.1:8000/eden/training/indexcontrollers/training.pydef index(): return dict() Pass control to a view template SahanaCamp NYC 20
  21. 21. Module Index Pageviews/training/index.html{{extend "layout.html"}}<H1>Welcome to the Training Module</H1><UL><LI>Browse the Course List</UL> HTML with Python inside {{..}} Extend layout.html for basic look and feel SahanaCamp NYC 21
  22. 22. Module Index Pageviews/training/index.html{{extend "layout.html"}}<H2>Welcome to the Training Module</H2><UL><LI>Browse the {{=A("Course List",_href=URL(c="training", f="course"))}}</UL> SahanaCamp NYC 22
  23. 23. ResourcesDominic KoenigSahanaCamp NYC 23
  24. 24. ComponentsParticipants of a Course SahanaCamp NYC 24
  25. 25. ComponentsParticipants of a Course SahanaCamp NYC 25
  26. 26. Componentsmodels/training.pytablename = "training_participant"db.define_table(tablename, s3db.pr_person_id(), Field("course_id", db.training_course ) )s3db.add_component("training_participant", training_course="course_id") SahanaCamp NYC 26
  27. 27. Resource Headercontrollers/training.pydef course_rheader(r): if r.record: tabs = [("Basic Details", None), ("Participants", "participant") ] rheader_tabs = s3_rheader_tabs(r, tabs) rheader = DIV(TABLE( TR(TH("Name: "), r.record.name), ), rheader_tabs) return rheader SahanaCamp NYC 27
  28. 28. Resource Headercontrollers/training.pydef course(): return s3_rest_controller(rheader=course_rheader)http://127.0.0.1:8000/eden/training/course/1/participant SahanaCamp NYC 28
  29. 29. Modifying Existing Applications Fran Boon fran@sahanafoundation.org SahanaCamp NYC 29
  30. 30. Which file do I edit?Each module will have:  Model: modules/eden/modulename.py  View: views/modulename/index.html There may be additional view files for custom pages  Controller: controllers/modulename.py SahanaCamp NYC 30
  31. 31. Web2Py URL Mapping http://host/application/controller/functioneg: http://127.0.0.1:8000/eden/default/index  Model: not applicable here  View: web2py/applications/eden/views/default/index.html  Controller: web2py/applications/eden/controllers/default.py  Function: def index(): SahanaCamp NYC 31
  32. 32. Sahana Eden URL Mapping http://host/eden/module/resourceeg: http://127.0.0.1:8000/eden/org/site  Model: web2py/applications/eden/modules/eden/org.py  tablename = "org_site"  View: not applicable here  Controller: web2py/applications/eden/controllers/org.py  Function: def site(): return s3_rest_controller() SahanaCamp NYC 32
  33. 33. ViewsGeneric View:web2py/applications/eden/views/_list_create.htmlIf you want to create a custom view then:Custom View:web2py/applications/eden/views/org/site_list_create.html SahanaCamp NYC 33
  34. 34. Edit a Field Labelmodules/eden/org.pytablename = "org_organisation"... Field("donation_phone", label = T("Donation Phone Number"), SahanaCamp NYC 34
  35. 35. Hide a Fieldmodules/eden/org.pytablename = "org_office"... Field("type", "integer readable=False, writable=False, label=T("Type")), SahanaCamp NYC 35
  36. 36. Add a New Fieldmodules/eden/org.pytablename = "org_organisation"... Field("facebook", label=T("Facebook Page")), SahanaCamp NYC 36
  37. 37. Edit the Menusmodules/eden/menus.pydef org(self): """ ORG / Organization Registry """ return M(c="org")( M("Organizations", f="organisation")( M("New", m="create"), M("List All"), M("Search", m="search"), M("Import", m="import") ), M("Venues", f="office")( M("New", m="create"), M("List All"), #M("Search", m="search"), M("Import", m="import") ), ) SahanaCamp NYC 37
  38. 38. Git and GitHub Fran Boonfran@sahanafoundation.org SahanaCamp NYC 38
  39. 39. AgendaInstalling GitCreating your own BranchSharing your Code with the Community SahanaCamp NYC 39
  40. 40. Installing GitGitHub.com has excellent instructionsCreate SSH public/private keysssh-keygen -t rsa -C “my_email@email.com” SahanaCamp NYC 40
  41. 41. Creating your Branchhttps://github.com/flavour/edenGet local copy: git clone git@github.com:myname/eden.gitStay up date: git pull upstream master SahanaCamp NYC 41
  42. 42. Sharing your CodeCommit code locally: git commit -aPush to GitHub: git pushSubmit Pull Request to get code merged into Trunk SahanaCamp NYC 42
  43. 43. SahanaCamp NYC 43

×