tech 2 - introduction to the code
DESCRIPTION
TRANSCRIPT
![Page 2: Tech 2 - Introduction to the Code](https://reader034.vdocuments.us/reader034/viewer/2022042623/54b70d7f4a7959ad588b45fe/html5/thumbnails/2.jpg)
22SahanaSahanaCampCamp Viet NamViet Nam
Installinga
Developer Environment
http://eden.sahanafoundation.org/wiki/InstallationGuidelines
![Page 3: Tech 2 - Introduction to the Code](https://reader034.vdocuments.us/reader034/viewer/2022042623/54b70d7f4a7959ad588b45fe/html5/thumbnails/3.jpg)
SahanaSahanaCampCamp Viet NamViet Nam
Architecture
Operating System
Database
Programming Language
Web Framework
Sahana Eden
Web Server n/a
Application
Web2Py
Python
SQLite
Windows, Linux or Mac
![Page 4: Tech 2 - Introduction to the Code](https://reader034.vdocuments.us/reader034/viewer/2022042623/54b70d7f4a7959ad588b45fe/html5/thumbnails/4.jpg)
SahanaSahanaCampCamp Viet NamViet Nam
Installation processWizard on Wiki to select correct instructions:http //eden.sahanafoundation.org/wiki/InstallationGuidelines:
Bootable USB
Windows Developer Installer
Eden-Python-Installer-Dev.exe
Mac, Linux Follow instructions to install from source
Virtual Machine
![Page 5: Tech 2 - Introduction to the Code](https://reader034.vdocuments.us/reader034/viewer/2022042623/54b70d7f4a7959ad588b45fe/html5/thumbnails/5.jpg)
55SahanaSahanaCampCamp Viet NamViet Nam
![Page 6: Tech 2 - Introduction to the Code](https://reader034.vdocuments.us/reader034/viewer/2022042623/54b70d7f4a7959ad588b45fe/html5/thumbnails/6.jpg)
SahanaSahanaCampCamp Viet NamViet Nam
Editor / DebuggerNotepad good basic editor for Windows++Eclipse allows advanced debugging: set breakpoints and step through code
http //eden.sahanafoundation.org/wiki/DeveloperGuidelinesEclipse:
Firebug allows advanced debugging of CSS and JavaScript view AJAX requests
edit CSS in realtime
browse DOM
set breakpoints and step through code
![Page 7: Tech 2 - Introduction to the Code](https://reader034.vdocuments.us/reader034/viewer/2022042623/54b70d7f4a7959ad588b45fe/html5/thumbnails/7.jpg)
SahanaSahanaCampCamp Viet NamViet Nam
Edit the Menus
modules/s3menus.py
def 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") ), )
![Page 8: Tech 2 - Introduction to the Code](https://reader034.vdocuments.us/reader034/viewer/2022042623/54b70d7f4a7959ad588b45fe/html5/thumbnails/8.jpg)
88SahanaSahanaCampCamp Viet NamViet Nam
Building
your own
Module!http://en.flossmanuals.net/sahana-eden/building-a-new-application/
![Page 9: Tech 2 - Introduction to the Code](https://reader034.vdocuments.us/reader034/viewer/2022042623/54b70d7f4a7959ad588b45fe/html5/thumbnails/9.jpg)
SahanaSahanaCampCamp Viet NamViet Nam
Whitespace Matters
Unlike other languages which use parentheses to delimit code blocks {...}, Python instead uses White Space
![Page 10: Tech 2 - Introduction to the Code](https://reader034.vdocuments.us/reader034/viewer/2022042623/54b70d7f4a7959ad588b45fe/html5/thumbnails/10.jpg)
SahanaSahanaCampCamp Viet NamViet Nam
Debug Mode
models/000_config.py
settings.base.debug = True
Reloads modules/s3db every request
CSS & JavaScript unminified
![Page 11: Tech 2 - Introduction to the Code](https://reader034.vdocuments.us/reader034/viewer/2022042623/54b70d7f4a7959ad588b45fe/html5/thumbnails/11.jpg)
SahanaSahanaCampCamp Viet NamViet Nam
Training ModuleResource Course: ' ' Name
Date / Time
Location Venue: Facilitator
Welcome Pack
![Page 12: Tech 2 - Introduction to the Code](https://reader034.vdocuments.us/reader034/viewer/2022042623/54b70d7f4a7959ad588b45fe/html5/thumbnails/12.jpg)
SahanaSahanaCampCamp Viet NamViet Nam
Define the Basic Data Model
models/training.py
tablename = "training_course"db.define_table(tablename, Field("name"), Field("start"), Field("facilitator"), )
Table Name :module resource_ Database migrated automatically' '
![Page 13: Tech 2 - Introduction to the Code](https://reader034.vdocuments.us/reader034/viewer/2022042623/54b70d7f4a7959ad588b45fe/html5/thumbnails/13.jpg)
SahanaSahanaCampCamp Viet NamViet Nam
Add a Controller
controllers/training.py
def course():
return s3_rest_controller()
Functions map URLs to code& resources
![Page 14: Tech 2 - Introduction to the Code](https://reader034.vdocuments.us/reader034/viewer/2022042623/54b70d7f4a7959ad588b45fe/html5/thumbnails/14.jpg)
SahanaSahanaCampCamp Viet NamViet Nam
Try it out!http //127.0.0.1 8000/eden/training/course: :
List
Create
Read
Update
Delete
![Page 15: Tech 2 - Introduction to the Code](https://reader034.vdocuments.us/reader034/viewer/2022042623/54b70d7f4a7959ad588b45fe/html5/thumbnails/15.jpg)
SahanaSahanaCampCamp Viet NamViet Nam
Other Formats
http //127.0.0.1 8000/eden/training/course: : .xls
http //127.0.0.1 8000/eden/training/course: : .xml
http //127.0.0.1 8000/eden/training/course: : .json
![Page 16: Tech 2 - Introduction to the Code](https://reader034.vdocuments.us/reader034/viewer/2022042623/54b70d7f4a7959ad588b45fe/html5/thumbnails/16.jpg)
SahanaSahanaCampCamp Viet NamViet Nam
Field Types
models/training.py
Field("name"), s3base.s3_date("start"), Field("welcome_pack", "upload"),
![Page 17: Tech 2 - Introduction to the Code](https://reader034.vdocuments.us/reader034/viewer/2022042623/54b70d7f4a7959ad588b45fe/html5/thumbnails/17.jpg)
SahanaSahanaCampCamp Viet NamViet Nam
Field Labels
models/training.py
S3base.s3_date("start", label=T("Start Date")),
![Page 18: Tech 2 - Introduction to the Code](https://reader034.vdocuments.us/reader034/viewer/2022042623/54b70d7f4a7959ad588b45fe/html5/thumbnails/18.jpg)
SahanaSahanaCampCamp Viet NamViet Nam
Links to other Resources
models/training.py
Field("name"), s3db.pr_person_id(label="Facilitator"),
![Page 19: Tech 2 - Introduction to the Code](https://reader034.vdocuments.us/reader034/viewer/2022042623/54b70d7f4a7959ad588b45fe/html5/thumbnails/19.jpg)
SahanaSahanaCampCamp Viet NamViet Nam
Pivot Table Reports
http //127.0.0.1 8000/eden/training/course: : report/
![Page 20: Tech 2 - Introduction to the Code](https://reader034.vdocuments.us/reader034/viewer/2022042623/54b70d7f4a7959ad588b45fe/html5/thumbnails/20.jpg)
SahanaSahanaCampCamp Viet NamViet Nam
Mapsmodels/training.py
Field("name"),s3db.gis_location_id(),
http //127.0.0.1 8000/eden/training/course: : map/
![Page 21: Tech 2 - Introduction to the Code](https://reader034.vdocuments.us/reader034/viewer/2022042623/54b70d7f4a7959ad588b45fe/html5/thumbnails/21.jpg)
2121SahanaSahanaCampCamp Viet NamViet Nam
Which File do I Edit?
http://en.flossmanuals.net/sahana-eden/customisation/
![Page 22: Tech 2 - Introduction to the Code](https://reader034.vdocuments.us/reader034/viewer/2022042623/54b70d7f4a7959ad588b45fe/html5/thumbnails/22.jpg)
2222SahanaSahanaCampCamp Viet NamViet Nam
![Page 23: Tech 2 - Introduction to the Code](https://reader034.vdocuments.us/reader034/viewer/2022042623/54b70d7f4a7959ad588b45fe/html5/thumbnails/23.jpg)
SahanaSahanaCampCamp Viet NamViet Nam
Model View Controller
Each module will have: Model : modules/s3db/modulename.py
Defines the data model
Controller : controllers/modulename.py Links URLs to resources
Views : views/modulename/index.html HTML templates with embedded python code
There may be additional view files for custom pages
![Page 24: Tech 2 - Introduction to the Code](https://reader034.vdocuments.us/reader034/viewer/2022042623/54b70d7f4a7959ad588b45fe/html5/thumbnails/24.jpg)
SahanaSahanaCampCamp Viet NamViet Nam
Web2Py URL Mapping
e.g.: http://127.0.0.1:8000/eden/default/index
Model : not applicable here Controller : web2py/applications/eden/controllers/default.py
Function: def index(): View : web2py/applications/eden/views/default/index.html
http://host/application/controller/function
![Page 25: Tech 2 - Introduction to the Code](https://reader034.vdocuments.us/reader034/viewer/2022042623/54b70d7f4a7959ad588b45fe/html5/thumbnails/25.jpg)
SahanaSahanaCampCamp Viet NamViet Nam
Sahana Eden URL Mapping
eg: http://127.0.0.1:8000/eden/org/site
Model: web2py/applications/eden/modules/s3db/org.py tablename = "org_site"
Controller: web2py/applications/eden/controllers/org.py Function: def site():
return s3_rest_controller()
View: not applicable here
http://host/eden/module/resource
![Page 26: Tech 2 - Introduction to the Code](https://reader034.vdocuments.us/reader034/viewer/2022042623/54b70d7f4a7959ad588b45fe/html5/thumbnails/26.jpg)
SahanaSahanaCampCamp Viet NamViet Nam
Views HTML with Python inside {{..}}
Extend layout.html for basic look and feel
views/training/index.html{{extend "layout.html"}}<H1>Welcome to the Training Module</H1><A href='{{=URL(f="course")}}'>Browse the Course List</A>
Resource Controllers use Generic Views:web2py/applications/eden/views/_list_create.html
Can customise these in the template:web2py/applications/eden/templates/template/views/_list_create.html
![Page 27: Tech 2 - Introduction to the Code](https://reader034.vdocuments.us/reader034/viewer/2022042623/54b70d7f4a7959ad588b45fe/html5/thumbnails/27.jpg)
SahanaSahanaCampCamp Viet NamViet Nam
Edit a Field Label
modules/s3db/org.py
tablename = "org_organisation"... Field("donation_phone", label = T("Donation Phone Number"),
![Page 28: Tech 2 - Introduction to the Code](https://reader034.vdocuments.us/reader034/viewer/2022042623/54b70d7f4a7959ad588b45fe/html5/thumbnails/28.jpg)
SahanaSahanaCampCamp Viet NamViet Nam
Hide a Field
modules/s3db/org.py
tablename = "org_office"... Field("type", "integer readable=False, writable=False, label=T("Type")),
![Page 29: Tech 2 - Introduction to the Code](https://reader034.vdocuments.us/reader034/viewer/2022042623/54b70d7f4a7959ad588b45fe/html5/thumbnails/29.jpg)
SahanaSahanaCampCamp Viet NamViet Nam
Add a New Field
modules/s3db/org.py
tablename = "org_organisation"... Field("facebook", label=T("Facebook Page")),
![Page 30: Tech 2 - Introduction to the Code](https://reader034.vdocuments.us/reader034/viewer/2022042623/54b70d7f4a7959ad588b45fe/html5/thumbnails/30.jpg)
3030SahanaSahanaCampCamp Viet NamViet Nam
Git
Controlled Updates
http://eden.sahanafoundation.org/wiki/DeveloperGuidelines/Git
![Page 31: Tech 2 - Introduction to the Code](https://reader034.vdocuments.us/reader034/viewer/2022042623/54b70d7f4a7959ad588b45fe/html5/thumbnails/31.jpg)
SahanaSahanaCampCamp Viet NamViet Nam
Installing GitGitHub.com has excellent instructions
Create SSH public/private keysssh-keygen -t rsa -C "[email protected]"
![Page 32: Tech 2 - Introduction to the Code](https://reader034.vdocuments.us/reader034/viewer/2022042623/54b70d7f4a7959ad588b45fe/html5/thumbnails/32.jpg)
SahanaSahanaCampCamp Viet NamViet Nam
Creating your Branchhttps //github.com/flavour/eden:
Get local copy : git clone [email protected]:myname/eden.gitStay up date : git pull upstream master
![Page 33: Tech 2 - Introduction to the Code](https://reader034.vdocuments.us/reader034/viewer/2022042623/54b70d7f4a7959ad588b45fe/html5/thumbnails/33.jpg)
SahanaSahanaCampCamp Viet NamViet Nam
Updating your ServerCommit code locally : git commit -aPush to GitHub : git pushPull on Server : git pull
![Page 34: Tech 2 - Introduction to the Code](https://reader034.vdocuments.us/reader034/viewer/2022042623/54b70d7f4a7959ad588b45fe/html5/thumbnails/34.jpg)
SahanaSahanaCampCamp Viet NamViet Nam
Sharing your CodeCommit code locally : git commit -aPush to GitHub : git pushSubmit Pull Request to get code merged into Trunk
![Page 35: Tech 2 - Introduction to the Code](https://reader034.vdocuments.us/reader034/viewer/2022042623/54b70d7f4a7959ad588b45fe/html5/thumbnails/35.jpg)