Web2py: Ideas We Stole - Ideas We Had
Web2py: Ideas We Stole - Ideas We Had
Web2py: Ideas We Stole - Ideas We Had
web2py
Main features
One Instance - Many Applications (hot plug and play)
Web based Integrated Development Environment Web based Database administration (for each app) Each application can connect to multiple Databases Writes SQL for you Strong on Security (no SQL Injections, XSS, CSRF, ..., audited) Built-in ticketing system (logs all errors) Runs everywhere (it is written in Python) Requires NO Installation (just download and unzip) Has no coniguration files and no third party dependencies Can run off a USB drive Always backward compatible (since 2007 and on...) 50+ of developers already involved
Thursday, July 14, 2011
Admin
wizard
new app
upload app
Included APIs
generation and parsing: HTML / XML / RSS / JSON web services: JSON / JSON-RPC / XML / XML-RPC / AMF document generation WIKI, CSV, RTF, LATEX, PDF 10 different SQL dialects and Google App Engine Role based access control with login plugins local, OpenID, OAuth
1 and 2, Janrain, LDAP Consumer + Provider Central Authentication Service
sending SMS, accepting Credit Card payments internationalization, cron jobs, multi-tenancy, ...
web2py Architecture
User Applications
welcome
examples
admin
Core Libraries HTTP request, HTTP response, session, cookies, internationalization, cache, authentication, authorization, web forms, template language, helpers, database APIs, web services APIs, etc. rocket (ssl enabled web server) API for third party servers (Apache,...)
python interpreter
web2py modules
web2py modules
web2py modules
web2py modules
web2py modules
web2py Architecture
User Applications
welcome
examples
admin
user dened
...
Core Libraries HTTP request, HTTP response, session, cookies, internationalization, Scaffolding cache, authentication, authorization, web forms, template language, helpers, Application database APIs, web services APIs, etc. rocket (ssl enabled web server) API for third party servers (Apache?)
python interpreter
web2py Architecture
User Applications
welcome
examples
admin
user dened
...
uploaded
Core Libraries HTTP request, HTTP response, session, cookies, internationalization, be Applications can cache, authentication, authorization, web forms, template language,and installed downloaded helpers, database APIs, web services APIs, etc. remotely rocket (ssl enabled web server) API for third party servers (Apache?)
python interpreter
web2py Architecture
User Applications
welcome
examples
admin
user dened
...
uploaded
Core Libraries HTTP request, HTTP of ofcial session, cookies, internationalization, entire clone response, cache, authentication,with running web forms, template language, helpers, web site authorization, database examples APIs, web services APIs, etc. rocket (ssl enabled web server) API for third party servers (Apache?)
python interpreter
web2py Architecture
User Applications
welcome
examples
admin
user dened
...
uploaded
Core Libraries web based HTTP request, HTTP response, session, cookies, internationalization, Integrated cache, authentication, authorization, web forms, template language, helpers, Development database APIs, web services APIs, etc. Environment rocket (ssl enabled web server) API for third party servers (Apache?)
python interpreter
web2py Architecture
User Applications
Core Libraries HTTP request, HTTP response, session, cookies, internationalization, cache, authentication, authorization, web forms, template language, helpers, database APIs, web services APIs, etc. rocket (ssl enabled web server) API for third party servers (Apache?)
python interpreter
Admin - Design
plugin_wiki (CMS)
web2py applications
plugins
Architecture of Applications
User Applications
user application Models Controllers Views Translations Static Files (media) Plugins Data appadmin
Field types include: string, text, integer, double, date, datetime, time, boolean, password, upload, blob, reference, list:string, list:interger, list:reference
Architecture of Applications
User Applications user application Models Controllers Views Translations Static Files (media) Plugins Data appadmin crud.create, crud.update, crud.select, crud.search, ... Role Based Access Control API Description of application logic Example: @auth.requires_login() def index(): # http://..../index form = crud.create(db.friend) friends = db(db.friend).select() return locals()
Architecture of Applications
User Applications user application Models Controllers Views Translations Static Files (media) Plugins Data appadmin embeds and renders any object in the page full python allowed in {{...python...}} including loops and function denitions. Description of data presentation Example: {{extend 'layout.html'}} <h1>{{=T('My Friends')}}</h1> <h2>New Friend</h2> {{=form}} <h2>Current Friends</h2> {{=friends}}
Architecture of Applications
User Applications user application Models Controllers Views Translations Static Files (media) Plugins Data appadmin Translations for text in the application - "my friends" - "i miei amici" - "mis amigos" - "meus amigos" - "mes amis" - "meine freunde" - ... - "maraki zangu"
Architecture of Applications
User Applications user application Models Controllers Views Translations Static Files (media) Plugins Data appadmin Static les distributed with the application and/or uplodaded by users: images movies audio les css les js code (scaffold includes jQuery) ....
Architecture of Applications
User Applications user application Models Controllers Views Translations Static Files (media) Plugins Data appadmin Any subset of an application can be packaged and can be distributed. This is called a plugin. Often plugins dene components, i.e. functional elements that can be embedded in pages. Example: plugin_wiki adds a CMS to you app plugin_mobile makes it iphone look-alike
Architecture of Applications
User Applications user application Models Controllers Views Translations Static Files (media) Plugins Data appadmin Includes: databases (SQlite, MySQL, PostgreSQL, Oracle, MSSQL, DB2, Firebird, MyBase, Informix, Google App Engine) metadata for automatic migrations cache
Architecture of Applications
User Applications user application Models Controllers Views Translations Static Files (media) Plugins Data appadmin default web based interface to your data
cd /path/to/demo wget -O web2py_src.zip http://web2py.com/examples/static/web2py_src.zip unzip -o -q web2py_src.zip cd web2py python web2py.py -a hello -p 8000 & cd applications mkdir friends cp -r welcome/* friends/ cd friends echo "db.define_table('friend',Field('name'))" > models/db_friends.py echo " @auth.requires_login() def index(): form = crud.create(db.friend) friends = db(db.friend).select() return locals() " > controllers/main.py mkdir views/main echo " {{extend 'layout.html'}} <h1>{{=T('My Friends')}}</h1> <h2>New Friend</h2> {{=form}} <h2>Current Friends</h2> {{=friends}} " > views/main/index.html
Controllers
Django (view in MTV)
def index(request): entry_id = request.GET['entry_id'] entry = Entry.objects.get(pk=entry_id) output = entry.name return HttpResponse(output)
def index(): entry_id = request.get_vars.entry_id or redirect(URL('error')) entry = Entry(entry_id) output = entry.name return dict(output=output) # defaults to generic template
Templates
Mako (template in MTV)
<%inherit file="base.html"/> <%def name="makerow(k)"> <tr> <td>${k}</td> <td>${k*k}</td> </tr> </%def> <% numbers = range(0,10) %> <table> % for k in numbers: ${makerow(k)} % endfor </table>
App-Admin
Django web2py
Django "admin" designed for public access web2py "app-admin" designed for administrator access only CRUD components from appadmin can be embedded in apps web2py "app-admin" not to be confused with web2py's "admin"
Thursday, July 14, 2011
Models
Django (model)
class Entry(models.Model): name = models.CharField(max_length=255,null=False) body = models.TextField() image = models.ImageField() pub_date = models.DateTimeField() rating = models.IntegerField()
web2py (model)
Entry = db.define_table('entry', Field('name',length=255,notnull=True), Field('body','text'), Field('image','upload',requires=IS_IMAGE()), Field('pub_date','datetime'), Field('rating','integer')]
Queries
Django (model)
q = Entry.objects.filter(headline__startswith="What") q = q.filter(pub_date__lte=datetime.now()) q = q.exclude(body__icontains="food") print q
web2py (model)
q = Entry.headline.startswith("What") q = q & (Entry.pub_date<datetime.now()) q = q & (!Entry.body.contains("food")) print db(q).select()
Thread Locals
Flask (proxies to objects that are local to a specic context)
from flask import request with app.request_context(environ): assert request.method == 'POST'
web2py (thread-locals)
from gluon import current assert current.request.env.http_method == 'POST'
Multi-version / No-conflicts
https://github.com/mitsuhiko/multiversion
import multiversion multiversion.require_version('mylib', '1.0') import mylib
web2py (each app can ship with its own version of libraries)
# app 1 import mylib # app 2 import mylib # from applications/app1/modules/
# from applications/app2/modules/
Each app ships with its own modules/ folder. Not added to sys.path No conflicts One web2py instance
Thursday, July 14, 2011
@auth.requires_login() @auth.requires_membership(role='secret agent') @auth.requires_permission('kill', 'bad_people', all) def test(): return 'done'
Web Services
For any function @service.json @service.xml @service.jsonrpc @service.xmlrpc @service.soap @service.amfrpc3('domain') def add(a,b): return a+b
Record Versioning
Store all previous version of each record with names of the user
who changed and timestamp of the change
component
In page {{=LOAD('plugin','component',user_signature=True)}}
Federated Authentication
Any application can be both a provider and a client for CAS 2.0 Other federated authentication mechanism available as clients
Multi-tenancy
All records are filtered based on tenant ownship Tenant identified for example by domain name Tables can be shared between tenant or not http://domain1 or http://domain2 (same app, different data)
Thursday, July 14, 2011
GAE Deployment
upload to GAE
Web translation
english italian
Error logging
Conclusions
web2py has been abround for since 2007 +50% was rewritten in 2010 while mantaining backward compatibility Some like it, some find it useful Give it a try!