SlideShare ist ein Scribd-Unternehmen logo
1 von 26
Sahana Eden:
Introduction to the Code
5 November 2010, Sahana Camp
Fran Boon
fran@sahanafoundation.org
Emergency
We have to build an application by lunchtime!
Agenda
• Web2Py execution model
• S3 REST Controller
– Model
– Controller
– View
Web2Py Execution Model
1. All Models executed every request
– In alphabetical order
– Within web2py environment
2. The Controller is executed
3. The View template is parsed
4. (HTML) page returned to client
Models
• Define Tables in Database
Live Migrations:
- Tables created/altered in database
Resources
• Common Resources from other Models
– Person
• Group
– Location
– Organisation
– Site
• Hospital
• Shelter
S3 REST Controller
• Args:
– /update, /create, /delete
• HTTP verbs:
– GET, PUT (POST), DELETE
• Representations:
– .html, .json, .xml, .xls, .pdf
Adding a new application
• Vehicle Tracking System
• Name: vts
• Resources:
– vehicle
– driver
– location
Model: Define Table
models/vts.py
# Vehicle resource
table = db.define_table("vts_vehicle",
Field("registration"),
Field("make"),
Field("model"),
Field("supplier"),
)
Controller: S3 REST
controllers/vts.py
def vehicle():
return s3_rest_controller("vts", "vehicle")
View
None needed at 1st – can RAD without them
& then polish later 
Try:
http://127.0.0.1:8000/eden/vts/vehicle
1. Create a vehicle.
2. View in different formats:
– .json, .xml, .xls, .pdf
Coffee
Views: S3 REST
• REST has default views
– create.html
– display.html
– list.html
– list_create.html
– update.html
Views
• Python code inside {{ }} is parsed server-
side
• Views can extend & include other views
• Extend ‘layout’ for overall look/feel
{{extend "layout.html"}}
Views: Custom
• They can also be customised:
views/vts/vehicle_list_create.html
{{extend "layout.html"}}
{{rheader="Register a new vehicle in the system:"}}
{{include "_list_create.html"}}
Model: SQL constraints
models/vts.py
table = db.define_table("vts_vehicle",
Field("registration", unique=True),
Field("make"),
Field("model"),
Field("supplier"),
)
Model: Field Types
models/vts.py
table = db.define_table("vts_vehicle",
Field("registration", unique=True),
Field("make"),
Field("model"),
Field("purchase_date", "date"),
Field("supplier"),
)
Model: Default Values
models/vts.py
table = db.define_table("vts_vehicle",
Field("registration", unique=True),
Field("make"),
Field("model"),
Field("purchase_date", "date",
default=request.utcnow),
Field("supplier"),
)
models/vts.py
…
db.vts_vehicle.registration.label = T("License Plate")
Labels
Controller: Comment
controllers/vts.py
def vehicle():
db.vts_vehicle.registration.comment = 
DIV(_class="tooltip", _title="Help text here")
return s3_rest_controller("vts", "vehicle")
How do we Navigate?
• Modules menu
• Modules list on frontpage
• Menu within Module
Enable Module
models/000_config.py
deployment_settings.modules = Storage(
…
vts = Storage(
name_nice = "Vehicle Tracking System",
description = "Track vehicles",
module_type = 10
),
…
)
Index page
controllers/vts.py
module = request.controller
def index():
"Custom View"
module_name = 
deployment_settings.modules[module].name_nice
return dict(module_name=module_name)
View
views/vts/index.html
{{extend "layout.html"}}
{{=H2(T(module_name))}}
<p>This module allows users to track their vehicles</p>
{{=LI(A("List Vehicles", _href=URL(r=request,
f="vehicle")))}}
Controller: Menu
controllers/vts.py
response.menu_options = [
[T("Vehicles"), False, URL(r=request, f="vehicle"),[
[T("List"), False, URL(r=request, f="vehicle")],
[T("Add"), False, URL(r=request, f="vehicle",
args="create")] ]]]
Lunch

Weitere ähnliche Inhalte

Was ist angesagt?

Was ist angesagt? (7)

Editable Documents on the Web
Editable Documents on the WebEditable Documents on the Web
Editable Documents on the Web
 
Azure DocumentDB for Healthcare Integration - Part 2
Azure DocumentDB for Healthcare Integration - Part 2Azure DocumentDB for Healthcare Integration - Part 2
Azure DocumentDB for Healthcare Integration - Part 2
 
Visualforce
VisualforceVisualforce
Visualforce
 
Scheduled Jobs in Azure
Scheduled Jobs in AzureScheduled Jobs in Azure
Scheduled Jobs in Azure
 
SharePoint 2013 Javascript Object Model
SharePoint 2013 Javascript Object ModelSharePoint 2013 Javascript Object Model
SharePoint 2013 Javascript Object Model
 
Couch db
Couch dbCouch db
Couch db
 
The ART of Modern Azure Deployments
The ART of Modern Azure DeploymentsThe ART of Modern Azure Deployments
The ART of Modern Azure Deployments
 

Andere mochten auch

Introduction to Sahana Eden
Introduction to Sahana EdenIntroduction to Sahana Eden
Introduction to Sahana Eden
AidIQ
 
Tech 2 - Introduction to the Code
Tech 2 - Introduction to the CodeTech 2 - Introduction to the Code
Tech 2 - Introduction to the Code
AidIQ
 
Tech 1 - Deploying Sahana Eden
Tech 1  - Deploying Sahana EdenTech 1  - Deploying Sahana Eden
Tech 1 - Deploying Sahana Eden
AidIQ
 
Bombeiros Workshop - Introduction to Sahana Eden
Bombeiros Workshop - Introduction to Sahana EdenBombeiros Workshop - Introduction to Sahana Eden
Bombeiros Workshop - Introduction to Sahana Eden
AidIQ
 
Simulation: Incidents (SahanaCamp 1.2)
Simulation: Incidents (SahanaCamp 1.2)Simulation: Incidents (SahanaCamp 1.2)
Simulation: Incidents (SahanaCamp 1.2)
AidIQ
 
Sahana camp simulation 1.1
Sahana camp simulation 1.1Sahana camp simulation 1.1
Sahana camp simulation 1.1
AidIQ
 
Simulation: Instructions ((SahanaCamp 1.2)
Simulation: Instructions ((SahanaCamp 1.2)Simulation: Instructions ((SahanaCamp 1.2)
Simulation: Instructions ((SahanaCamp 1.2)
AidIQ
 
General Sessions Hand Outs (SahanaCamp 1.2)
General Sessions Hand Outs (SahanaCamp 1.2)General Sessions Hand Outs (SahanaCamp 1.2)
General Sessions Hand Outs (SahanaCamp 1.2)
AidIQ
 
Sahana camp incident reporting exercise v3
Sahana camp incident reporting exercise v3Sahana camp incident reporting exercise v3
Sahana camp incident reporting exercise v3
AidIQ
 
Humanitarian Mapping - Sahana and OpenStreetMap
Humanitarian Mapping - Sahana and OpenStreetMapHumanitarian Mapping - Sahana and OpenStreetMap
Humanitarian Mapping - Sahana and OpenStreetMap
AidIQ
 
Inventory management system
Inventory management systemInventory management system
Inventory management system
copo7475
 

Andere mochten auch (14)

Introduction to Sahana Eden
Introduction to Sahana EdenIntroduction to Sahana Eden
Introduction to Sahana Eden
 
Tech 2 - Introduction to the Code
Tech 2 - Introduction to the CodeTech 2 - Introduction to the Code
Tech 2 - Introduction to the Code
 
Tech 1 - Deploying Sahana Eden
Tech 1  - Deploying Sahana EdenTech 1  - Deploying Sahana Eden
Tech 1 - Deploying Sahana Eden
 
Bombeiros Workshop - Introduction to Sahana Eden
Bombeiros Workshop - Introduction to Sahana EdenBombeiros Workshop - Introduction to Sahana Eden
Bombeiros Workshop - Introduction to Sahana Eden
 
Sahana Open Source Humanitarian Software Project - Pandemic Preparedness Forum
Sahana Open Source Humanitarian Software Project - Pandemic Preparedness ForumSahana Open Source Humanitarian Software Project - Pandemic Preparedness Forum
Sahana Open Source Humanitarian Software Project - Pandemic Preparedness Forum
 
Sahana Camp Radio Exercise
Sahana Camp Radio ExerciseSahana Camp Radio Exercise
Sahana Camp Radio Exercise
 
Simulation: Incidents (SahanaCamp 1.2)
Simulation: Incidents (SahanaCamp 1.2)Simulation: Incidents (SahanaCamp 1.2)
Simulation: Incidents (SahanaCamp 1.2)
 
Sahana camp simulation 1.1
Sahana camp simulation 1.1Sahana camp simulation 1.1
Sahana camp simulation 1.1
 
Simulation: Instructions ((SahanaCamp 1.2)
Simulation: Instructions ((SahanaCamp 1.2)Simulation: Instructions ((SahanaCamp 1.2)
Simulation: Instructions ((SahanaCamp 1.2)
 
General Sessions Hand Outs (SahanaCamp 1.2)
General Sessions Hand Outs (SahanaCamp 1.2)General Sessions Hand Outs (SahanaCamp 1.2)
General Sessions Hand Outs (SahanaCamp 1.2)
 
Sahana Camp Simulation
Sahana Camp SimulationSahana Camp Simulation
Sahana Camp Simulation
 
Sahana camp incident reporting exercise v3
Sahana camp incident reporting exercise v3Sahana camp incident reporting exercise v3
Sahana camp incident reporting exercise v3
 
Humanitarian Mapping - Sahana and OpenStreetMap
Humanitarian Mapping - Sahana and OpenStreetMapHumanitarian Mapping - Sahana and OpenStreetMap
Humanitarian Mapping - Sahana and OpenStreetMap
 
Inventory management system
Inventory management systemInventory management system
Inventory management system
 

Ähnlich wie Sahana Eden : Introduction to the Code (SahanaCamp 1.2)

MVC & SQL_In_1_Hour
MVC & SQL_In_1_HourMVC & SQL_In_1_Hour
MVC & SQL_In_1_Hour
Dilip Patel
 
Challenges of Simple Documents: When Basic isn't so Basic - Cassandra Targett...
Challenges of Simple Documents: When Basic isn't so Basic - Cassandra Targett...Challenges of Simple Documents: When Basic isn't so Basic - Cassandra Targett...
Challenges of Simple Documents: When Basic isn't so Basic - Cassandra Targett...
Lucidworks
 
WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...
Fabio Franzini
 

Ähnlich wie Sahana Eden : Introduction to the Code (SahanaCamp 1.2) (20)

SFScon 2020 - Nikola Milisavljevic - BASE - Python REST API framework
SFScon 2020 - Nikola Milisavljevic - BASE - Python REST API frameworkSFScon 2020 - Nikola Milisavljevic - BASE - Python REST API framework
SFScon 2020 - Nikola Milisavljevic - BASE - Python REST API framework
 
GHC
GHCGHC
GHC
 
MVC & SQL_In_1_Hour
MVC & SQL_In_1_HourMVC & SQL_In_1_Hour
MVC & SQL_In_1_Hour
 
SharePoint 2013 - What's New
SharePoint 2013 - What's NewSharePoint 2013 - What's New
SharePoint 2013 - What's New
 
ASP.NET Mvc 4 web api
ASP.NET Mvc 4 web apiASP.NET Mvc 4 web api
ASP.NET Mvc 4 web api
 
Office 365 Saturday (Sydney) - SharePoint framework – build integrated user e...
Office 365 Saturday (Sydney) - SharePoint framework – build integrated user e...Office 365 Saturday (Sydney) - SharePoint framework – build integrated user e...
Office 365 Saturday (Sydney) - SharePoint framework – build integrated user e...
 
Building RESTfull Data Services with WebAPI
Building RESTfull Data Services with WebAPIBuilding RESTfull Data Services with WebAPI
Building RESTfull Data Services with WebAPI
 
[Luca/Van Campenhoudt] Microsoft Flow Beyone the Limits: Tips, Pitfalls, Patt...
[Luca/Van Campenhoudt] Microsoft Flow Beyone the Limits: Tips, Pitfalls, Patt...[Luca/Van Campenhoudt] Microsoft Flow Beyone the Limits: Tips, Pitfalls, Patt...
[Luca/Van Campenhoudt] Microsoft Flow Beyone the Limits: Tips, Pitfalls, Patt...
 
Microsoft Flow best practices European Collaboration Summit 2018
Microsoft Flow best practices European Collaboration Summit 2018Microsoft Flow best practices European Collaboration Summit 2018
Microsoft Flow best practices European Collaboration Summit 2018
 
REST easy with API Platform
REST easy with API PlatformREST easy with API Platform
REST easy with API Platform
 
Building Your First App with MongoDB
Building Your First App with MongoDBBuilding Your First App with MongoDB
Building Your First App with MongoDB
 
06 web api
06 web api06 web api
06 web api
 
Challenges of Simple Documents: When Basic isn't so Basic - Cassandra Targett...
Challenges of Simple Documents: When Basic isn't so Basic - Cassandra Targett...Challenges of Simple Documents: When Basic isn't so Basic - Cassandra Targett...
Challenges of Simple Documents: When Basic isn't so Basic - Cassandra Targett...
 
Building APIs in an easy way using API Platform
Building APIs in an easy way using API PlatformBuilding APIs in an easy way using API Platform
Building APIs in an easy way using API Platform
 
Resting on your laurels will get you powned
Resting on your laurels will get you pownedResting on your laurels will get you powned
Resting on your laurels will get you powned
 
(ATS6-PLAT04) Query service
(ATS6-PLAT04) Query service (ATS6-PLAT04) Query service
(ATS6-PLAT04) Query service
 
WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...
 
Charla desarrollo de apps con sharepoint y office 365
Charla   desarrollo de apps con sharepoint y office 365Charla   desarrollo de apps con sharepoint y office 365
Charla desarrollo de apps con sharepoint y office 365
 
6 10-presentation
6 10-presentation6 10-presentation
6 10-presentation
 
Building APIs in an easy way using API Platform
Building APIs in an easy way using API PlatformBuilding APIs in an easy way using API Platform
Building APIs in an easy way using API Platform
 

Mehr von AidIQ

Sahana Eden : Introduction and Simulation A (SahanaCamp 1.2)
Sahana Eden : Introduction and Simulation A (SahanaCamp 1.2)Sahana Eden : Introduction and Simulation A (SahanaCamp 1.2)
Sahana Eden : Introduction and Simulation A (SahanaCamp 1.2)
AidIQ
 
Sahana Eden : Developer Environment (VM) (SahanaCamp 1.2)
Sahana Eden : Developer Environment (VM) (SahanaCamp 1.2)Sahana Eden : Developer Environment (VM) (SahanaCamp 1.2)
Sahana Eden : Developer Environment (VM) (SahanaCamp 1.2)
AidIQ
 
Sahana Eden : Deployment (SahanaCamp 1.2)
Sahana Eden : Deployment (SahanaCamp 1.2)Sahana Eden : Deployment (SahanaCamp 1.2)
Sahana Eden : Deployment (SahanaCamp 1.2)
AidIQ
 
Sahana Eden : Bug Reporting (SahanaCamp 1.2)
Sahana Eden : Bug Reporting (SahanaCamp 1.2)Sahana Eden : Bug Reporting (SahanaCamp 1.2)
Sahana Eden : Bug Reporting (SahanaCamp 1.2)
AidIQ
 
Sahana : Case Studies (SahanaCamp 1.2)
Sahana : Case Studies (SahanaCamp 1.2)Sahana : Case Studies (SahanaCamp 1.2)
Sahana : Case Studies (SahanaCamp 1.2)
AidIQ
 
Participatory programming
Participatory programmingParticipatory programming
Participatory programming
AidIQ
 
OpenStreetMap : Technical (SahanaCamp 1.2)
OpenStreetMap : Technical (SahanaCamp 1.2)OpenStreetMap : Technical (SahanaCamp 1.2)
OpenStreetMap : Technical (SahanaCamp 1.2)
AidIQ
 
OpenStreetMap : Sahana Mapping Client (SahanaCamp 1.2)
OpenStreetMap : Sahana Mapping Client (SahanaCamp 1.2)OpenStreetMap : Sahana Mapping Client (SahanaCamp 1.2)
OpenStreetMap : Sahana Mapping Client (SahanaCamp 1.2)
AidIQ
 
Implementing IT Solutions for Disaster Management (SahanaCamp 1.2)
Implementing IT Solutions for Disaster Management (SahanaCamp 1.2)Implementing IT Solutions for Disaster Management (SahanaCamp 1.2)
Implementing IT Solutions for Disaster Management (SahanaCamp 1.2)
AidIQ
 
BZR & LaunchPad : Sharing Your Work With Others (SahanaCamp 1.2)
BZR & LaunchPad : Sharing Your Work With Others (SahanaCamp 1.2)BZR & LaunchPad : Sharing Your Work With Others (SahanaCamp 1.2)
BZR & LaunchPad : Sharing Your Work With Others (SahanaCamp 1.2)
AidIQ
 
GHC Participant Training
GHC Participant TrainingGHC Participant Training
GHC Participant Training
AidIQ
 
Sahana sharing your work with others
Sahana   sharing your work with othersSahana   sharing your work with others
Sahana sharing your work with others
AidIQ
 
Sahana introduction to the code v2
Sahana   introduction to the code v2Sahana   introduction to the code v2
Sahana introduction to the code v2
AidIQ
 
Sahana community development process
Sahana   community development processSahana   community development process
Sahana community development process
AidIQ
 
OpenStreetMap louis liu
OpenStreetMap   louis liuOpenStreetMap   louis liu
OpenStreetMap louis liu
AidIQ
 
OpenStreetMap dongpo deng
OpenStreetMap   dongpo dengOpenStreetMap   dongpo deng
OpenStreetMap dongpo deng
AidIQ
 
Open GeoSMS slayer chuang
Open GeoSMS   slayer chuangOpen GeoSMS   slayer chuang
Open GeoSMS slayer chuang
AidIQ
 

Mehr von AidIQ (18)

Sahana Eden : Introduction and Simulation A (SahanaCamp 1.2)
Sahana Eden : Introduction and Simulation A (SahanaCamp 1.2)Sahana Eden : Introduction and Simulation A (SahanaCamp 1.2)
Sahana Eden : Introduction and Simulation A (SahanaCamp 1.2)
 
Sahana Eden : Developer Environment (VM) (SahanaCamp 1.2)
Sahana Eden : Developer Environment (VM) (SahanaCamp 1.2)Sahana Eden : Developer Environment (VM) (SahanaCamp 1.2)
Sahana Eden : Developer Environment (VM) (SahanaCamp 1.2)
 
Sahana Eden : Deployment (SahanaCamp 1.2)
Sahana Eden : Deployment (SahanaCamp 1.2)Sahana Eden : Deployment (SahanaCamp 1.2)
Sahana Eden : Deployment (SahanaCamp 1.2)
 
Sahana Eden : Bug Reporting (SahanaCamp 1.2)
Sahana Eden : Bug Reporting (SahanaCamp 1.2)Sahana Eden : Bug Reporting (SahanaCamp 1.2)
Sahana Eden : Bug Reporting (SahanaCamp 1.2)
 
Sahana : Case Studies (SahanaCamp 1.2)
Sahana : Case Studies (SahanaCamp 1.2)Sahana : Case Studies (SahanaCamp 1.2)
Sahana : Case Studies (SahanaCamp 1.2)
 
Participatory programming
Participatory programmingParticipatory programming
Participatory programming
 
OpenStreetMap : Technical (SahanaCamp 1.2)
OpenStreetMap : Technical (SahanaCamp 1.2)OpenStreetMap : Technical (SahanaCamp 1.2)
OpenStreetMap : Technical (SahanaCamp 1.2)
 
OpenStreetMap : Sahana Mapping Client (SahanaCamp 1.2)
OpenStreetMap : Sahana Mapping Client (SahanaCamp 1.2)OpenStreetMap : Sahana Mapping Client (SahanaCamp 1.2)
OpenStreetMap : Sahana Mapping Client (SahanaCamp 1.2)
 
Implementing IT Solutions for Disaster Management (SahanaCamp 1.2)
Implementing IT Solutions for Disaster Management (SahanaCamp 1.2)Implementing IT Solutions for Disaster Management (SahanaCamp 1.2)
Implementing IT Solutions for Disaster Management (SahanaCamp 1.2)
 
BZR & LaunchPad : Sharing Your Work With Others (SahanaCamp 1.2)
BZR & LaunchPad : Sharing Your Work With Others (SahanaCamp 1.2)BZR & LaunchPad : Sharing Your Work With Others (SahanaCamp 1.2)
BZR & LaunchPad : Sharing Your Work With Others (SahanaCamp 1.2)
 
GHC Participant Training
GHC Participant TrainingGHC Participant Training
GHC Participant Training
 
Exercise24
Exercise24Exercise24
Exercise24
 
Sahana sharing your work with others
Sahana   sharing your work with othersSahana   sharing your work with others
Sahana sharing your work with others
 
Sahana introduction to the code v2
Sahana   introduction to the code v2Sahana   introduction to the code v2
Sahana introduction to the code v2
 
Sahana community development process
Sahana   community development processSahana   community development process
Sahana community development process
 
OpenStreetMap louis liu
OpenStreetMap   louis liuOpenStreetMap   louis liu
OpenStreetMap louis liu
 
OpenStreetMap dongpo deng
OpenStreetMap   dongpo dengOpenStreetMap   dongpo deng
OpenStreetMap dongpo deng
 
Open GeoSMS slayer chuang
Open GeoSMS   slayer chuangOpen GeoSMS   slayer chuang
Open GeoSMS slayer chuang
 

Kürzlich hochgeladen

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Kürzlich hochgeladen (20)

Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 

Sahana Eden : Introduction to the Code (SahanaCamp 1.2)

Hinweis der Redaktion

  1. As well as being a suite of pre-built applications, Eden is also an Emergency Development Environment: a framework which can be used to rapidly build new ones to meet custom needs (as every emergency is different).
  2. Because all models are executed every request, it is important to minimise the amount of time taken to process them. Alphabetical order is to Manage the dependencies ‘In the Web2Py environment’ means no need to import most of the libraries in ‘gluon/’ & access to the global variables: request, session & response. First the parts of the Controller outside Functions are executed & then the relevant Function. Functions with no arguments are automatically visible via URLs No need to add a routes entry (unlike other frameworks, like Django) The Controller or View could also return XML (e.g. RSS or KML), JSON, PDF or XLS.
  3. Remember that after server-side Python finishes, we still have a lot of possibilities client-side with JavaScript. URL() is an example of an HTML ‘Helper’ object
  4. JS = JavaScript
  5. Deleted Columns / Tables simply Ignored Sahana Eden is Resource-centric
  6. Sahana Eden is Resource-centric
  7. Web Services, Mash-ups
  8. Create a new file in the Models folder called ‘vts.py’ & type in the text above. # 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. Create a new file in the Controllers folder called ‘vts.py’ & type in the text above.
  10. Note that you’ll need to Login to the system before you’re allowed to create a resource.
  11. These defaults are why we didn’t need any views for our application. Web2Py defaults to views/controller/function.html, but S3REST needs a different view per Method
  12. No need to learn another macro language Can Extend just a single other file Can Include many others
  13. 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
  14. 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
  15. Unique=True is a SQL-level constraint. Open your vts.py from the models directory & add the extra code above. Try adding multiple vehicles with the same registration. Validators are DAL-level constraints which provide server-side validation & some also provide client-side rendering & validation. These are automatically added with SQL constraints to produce nice error messages instead of tickets. Validators can also be added manually as: db.vts_vehicle.registration.requires = IS_NOT_IN_DB(…)
  16. 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 (This comes from the default IS_DATE() Validator) Add the extra code above to your file & refresh the page, now enter a date.
  17. Add the extra code above to your file & refresh the page to see the default value
  18. Add this to your model (under the table definition) & try it out. T() is to Internationalise the string
  19. Add the comment to your controller & try it out
  20. If you have time, then you can try out these CRUD strings…copy/paste from another model & then edit…see what effect this has on your module.
  21. 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)
  22. 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)
  23. 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?
  24. Add this text to your controller (outside the functions – e.g. at the top) & see what effect this has on your module.
  25. 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’).
  26. The alias ‘w2p’ runs: python web2py.py –S eden –M
  27. Don’t take effect until you db.commit()
  28. Copt this text into your model. Note the use of string substitution to define the tablename
  29. 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.
  30. 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
  31. 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
  32. 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.
  33. We can add additional fields into the link table.
  34. IS_ONE_OF provides the representation in the dropdown table.field.represent provides the representation in Display/List views Optimise the query – we know we only want a single record & a single field from that record
  35. Add this to your model underneath the definition of the Presence table & try out the URL. No need for dedicated presence() controller This can then be enhanced with the use of Tabs – look for rheader tabs in the source of other applications…
  36. Add this Resource Header definition to your Controller. Be careful to get the end brackets & commas right! ‘r’ is the resource
  37. Then plug it into the Controller
  38. Take a look at the HTML structure of the page in Firebug.