Pylons & ExtJS
PyCologne Vortrag Kln, 11.6.2008
smart:elligence Unternehmensberatung, Dsseldorf
Agenda
WSGI Basics & Framework Pylons die wichtigsten Komponenten Pylons Laufzeitumgebung, Applikations-Struktur ExtJS Basics ExtJS & Pylons AJAX Playground Go for the code, Luke...
27.06.08
smart:elligence Unternehmensberatung, Dsseldorf
Seite 2
WSGI - Basics
WSGI Server Web Server Web Client request (Apache) WSGI Application
callable(environ, start_response) def start_headers(): store status, headers, ... environ = dict(...) result = wsgiapp(environ, start_headers)
request
call()
read/manipulate environ[] create/add/change headers call start_response() create content as iterable
WSGI Server Web Client content Web Server (Apache)
content
for header in stored_headers: write(header) for data in result: write(data)
iterable
return iterable
start_response(status,response_headers,exc_info)
status = HTTP-Status (200, 404, ...) response_header= HTTP-Headers [ (name, value), ... ] exc_info = sys.exc_info() [in case of exceptions]
Enivron[]
WSGI-Var's: ["wsgi.input"] ["wsgi.error"] ["wsgi.version"] ... CGI-Var's: ["REQUEST_METHOD"] ["PATH_INFO"] ...
27.06.08
smart:elligence Unternehmensberatung, Dsseldorf
Seite 3
WSGI - Framework
Web Client
WSGI Server
def start_response() result = callable()
WSGI Framework
routing, logging, threads... def start_response() wsgiapp = selectapp() result = wsgiapp() call srv.start_response() return iterable
WSGI App (Error hdl)
callable() return iter()
WSGI App CMS
callable() return iter()
WSGI App Wiki
callable() return iter()
27.06.08
smart:elligence Unternehmensberatung, Dsseldorf
Seite 4
Pylons - Komponenten
Threaded HTTP Server WSGI Server - request dispatching, request chaining, subrequests - authentication - debugging, logging, exception handling Generic Template Engine Handling Allows multiple template languages
Paste
Buffet
Routes
Ruby-Style Routing m.connect('archives/:year/:month/:day', controller='archives', action='view', year=2004) Allows defaults Allows named routes (reuse) Allows url-creation h.url_for(controller="archives", year=2005) => <a>...</a> Session Handling In-Memory / file based session handling session["abc"] = mydata session.save()
Mako
Default Pylons Template Engine Based on "mighty", focused on templating alone
SQLAlchemy
Default SQL-Connector Object modell <> Relational modell mapping
Beaker
Webhelpers
Web-specific utilities "rails" - stuff scriptaculous, textile, htmlgen, ...
27.06.08
smart:elligence Unternehmensberatung, Dsseldorf
Seite 5
Pylons - Laufzeitumgebung
Web Client Web Server (Apache) Paster daemon Pylons Runtime
request => request obj + wsgi environment session. => Beaker sessions render() => Buffer render function g. => global object c. => request specific object h. => utility-functions, webhelpers ...
WSGI Application stack PylonsApp(ErrorHandler(Static_Url_Parser(Tr
anslogger(RegistryManager(...)))))
Pylons WSGI App
Routes
Models
access database
Controller.action(url_parameters)
get/store session data
Beaker session-obj
SQL-Alchemy
return render(template)
Buffet.render() e.g. mako.render()
return "string"
return render_result()
27.06.08
smart:elligence Unternehmensberatung, Dsseldorf
Seite 6
Pylons - Applikationsstruktur
Hauptverzeichnis\
data\ docs\ pyapp\ pyapp.egg-info\ development.ini setup.py ... config\ controllers\ lib\ model\ public\ templates\ tests\ Temp - compilierte Mako-Templates, Beaker-Sessions, ... Zielverzeichnis Dokumentation pyapp = Name der Pylons-Anwendung Egg-Daten fr Deployment Paster Konfiguration fr pyapp Anwendung easy_install setup.py Weitere Dateien (readme.txt ...) Konfigurations-Daten (environment, routes, middleware, ...) Applikationslogik Bibliothek, zentrale Klasse, globale Objekte Daten/Objektmodelle, SQLAlchemy-Mapping etc. Statische Inhalte (css, gif's, html, javascript) Template-Verzeichnis, z.B. MAKO-templates Anwendungs-Testcode
pyapp\
27.06.08
smart:elligence Unternehmensberatung, Dsseldorf
Seite 7
ExtJS - Basics
Umfangreiche Javascript-Bibliothek:
Zahlreiche GUI-Elemente (Treeview, Listen, Dropdowns, ...) Einfache Konfiguration von GUI-Elementen Extensive AJAX-Untersttzung Diverse Unterbibliotheken (Yahoo-UI, Google-UI) anwhlbar Lizenz: ursprnglich open source Inzwischen: dual licencing (open source-Lizenz nur auf Antrag)
27.06.08
smart:elligence Unternehmensberatung, Dsseldorf
Seite 8
Pylons / ExtJS AJAX Playground
Basis-Template erzeugt/referenziert extJS client code ExtJS Anwendung wird im Browser erzeugt ExtJS kommuniziert ber
normale give me HTML or <img> HTTP-requests JSON/AJAX requests ExtJS sendet AJAX request an URL mit HTTP-Parametern Routes steuert entsprechende Controller.Action an Ergebnisse (als dict) werden in JSON-Format konvertiert (Pylons bietet @jsonify decorator fr automatische Konvertierung) ExtJS bietet JSON-fhige Klassen (z.B. Treeviews) an ExtJS verarbeitet AJAX-callback asynchron und reagiert entsprechend Normales HTML ber Templates Statischer Content (.img, .html, .js, ...) AJAX-fokussiertes, ber JSON kommunizierter Content Dynamisch erzeugtes Bildmaterial (Charts o..)
Datenaustausch: per JSON
Content unterschiedlichen Typs:
27.06.08
smart:elligence Unternehmensberatung, Dsseldorf
Seite 9
Vielen Dank fr Ihre Aufmerksamkeit
27.06.08
smart:elligence Unternehmensberatung, Dsseldorf
Seite 10
smart:elligence Kontaktdaten
smart:elligence Unternehmensberatung Geschftsfhrer: Andrew Smart Goethestr. 55 40237 Dsseldorf
Tel 0211 617 9010 Mobil 0170 223 4440 Mail: smart@smartelligence.de
27.06.08
smart:elligence Unternehmensberatung, Dsseldorf
Seite 11