TurboGears2


                        Building
            Full Featured Web Applications
                    with TurboGears2
                 in a bunch of minutes




Alessandro Molina - @__amol__ - amol@turbogears.org
TurboGears2
● Framework for rapid development encouraging
   customization
● Object Dispatch based. Regular expressions can get
   messy, never write a regex anymore
● By default an XML template engine with error
   detection
● Declarative Models with transactional unit of work
● Built in Validation, Authentication, Authorization,
   Caching, Sessions, Migrations, MongoDB Support and
   many more.
Looking at the code
Serving /movie/3 as a webpage and /movie/3.json as
a json encoded response


class RootController(BaseController):

  @expose('myproj.templates.movie')
  @expose('json')
  @validate({'movie':SQLAEntityConverter(model.Movie)}
  def movie(self, movie, **kw):
    return dict(movie=movie, user=request.identity and request.identity['user'])
What it looks like
TurboGears for RAD
● 2.0 had sprox and tgext.crud: Flexible, but hard to use!
● 2.1 had many sprox improvements and added the
    EasyCrudRestController
●   2.1.4 had many hooks improvements that made tgext.
    pluggable possible!




With EasyCrudRestController and pluggable applications
rapid prototyping can be rapid for real
EasyCrudRestController
Aims at making possible to create full administrative
interfaces in a bunch of seconds
Easy CRUD
Minimal setup is minimal for real!


             from tgext.crud import EasyCrudRestController

             class GalleriesController(EasyCrudRestController):
               model = model.Gallery




This provides CRUD interface with Search, ordering and
autogenerated JSON Rest API for that model.
Custom CRUD
Customizing the Crud Controller can be done from the
__form_options__ and __table_options__ variables of the
class.
           class PhotosController(EasyCrudRestController):
             model = model.Photo
             allow_only = predicates.in_group('photos')
             title = "Manage Photos"
             keep_params = ['gallery']

             __form_options__ = {
               '__hide_fields__' : ['uid', 'author', 'gallery'],
               '__field_widget_types__' : {'image':FileField},
               '__field_validator_types__' : {'image':FieldStorageUploadConverter},
               '__field_widget_args__' : {'author':{'default':lambda:request.identity['user'].user_id}}
             }

             __table_options__ = {
               '__omit_fields__' : ['uid', 'author_id', 'gallery_id', 'gallery'],
               '__xml_fields__' : ['image'],
               'image': lambda filler,row: html.literal('‹img src="%s"/›' % row.image.thumb_url)
             }
Custom CRUD Result
Result is a web page to upload photos to a gallery with
uploaded image preview
Let's plug them all
CRUD tools provide a quick and easy way to prototype new
functions.

But... there are things which are not a plain CRUD, how can
you speed up their development?

Fastest solution is to have things already done by someone
else!

That's what pluggable applications are for
Pluggables
Pluggable applications provide ready made features that can
be plugged into your applications.
● Implemented as tgext.pluggable, if you don't use them
   they won't bother you
● As easy as plug(base_config, 'appname')
● They look a lot like a plain application and provide
   models, controllers, templates, helpers, partials,
   database bootstrap and so on.
● Creating one as easy as paster quickstart-pluggable
   appname
● Sadly supported only for SQLAlchemy storage backed,
   mongodb planned
Available Pluggables
tgapp-registration              tgapp-smallpress

Provides a registration     Provides multblog with
process with activation           WYSIWYG editor,
email. It's heavily        tagcloud, attachments,
customizable using                   drafts, future
hooks.                            publications and
                             Whoosh based search.




tgapp-fbauth                         tgapp-photos

facebook authentication,       Provides partials to
registration and                display photos and
connection to existing        photo galleries with
accounts.                   automatic thumbnails.
Available Pluggables
tgapp-userprofile                             libacr

Provides a basic profile       Provides a powerful
page and badge                    CMS where pages
for users with profile       are splitted into slices
picture took from                     each editable
facebook, gravatar or          and of its own type.
custom source.
                                  Custom slices and
                             new type of contents
 stroller                    can be easily created
                             directly from the CMS
 Provides eCommerce           itself without editing
 application with                             code.
 categories, multiple
 pictures for each product
 and orders management.
DebugBar
To improve developers life the first pluggable application
created has been the debugbar.
                                       ● Controller methods
                                         profiling
                                       ● Template Rendering
                                         timings
                                       ● Query inspector
                                       ● Request inspector
                                       ● and so on... The
                                         usual things you
                                         would expect from a
                                         debug bar!
Inventing Mode
How the debugbar relates to rapid prototyping?
Well, it makes life easier, but mostly... It provides the
inventing mode!

Place your browser and code editor side by side and start
experimenting, your changes will reflect into the browser in
real time and it will notify you when you broke something.
Creating pluggables
Once tgext.pluggable gets installed the quickstart-pluggable
command becames available.

Running quickstart-pluggable will create a package that
looks a lot like a TurboGears application but provides a
plugme method inside its __init__.py

plugme method is the entry point of your pluggable
application.


 def plugme(app_config, options):
   return dict(appid='plugtest', global_helpers=False)
Structure of a Pluggable
$ paster quickstart-pluggable plugtest

                                         Pluggable Applications controllers, root
                                         controller of the application is named
                                         RootController inside the root.py file and
                                         will be mounted as /plugtest

                                         Models of the pluggable applications, will
                                         be bound to the session of the master app

                                         Static files of the pluggable application,
                                         will be available at /_pluggable/plugtest




                                         Templates of the pluggable application,
                                         controllers can use them with standard
                                         expose syntax: @expose('plugtest.
                                         templates.index')
Structure of a Pluggable

           Here rely all the utility functions of the
           pluggable application. By default they are
           not exposed to the master application but
           are stille accessible as a python module

           bootstrap is automatically called when
           initializing the database of the master
           application.

           Pluggables can provide helpers which will
           be automatically available into the master
           application as h.plugtest.helpername

           Partials are evolved helpers, they provide logic
           and look like controllers with an exposed
           template. They are acceissible inside templates
           with h.call_partial('plugtest.partials:
           partialname')
Pluggable Utilities
tgext.pluggable provides a bunch of utilities that help when
working with pluggable applications to override part of their
aspect or behavior:

●   replace_template(base_config, 'otherapp.templates.about', 'myapp.
    templates.index')    permits to replace any template with another one,
    makes possible to change the look of any plugged web page
●   plug_url('plugtest', '/somewhere') makes possible to generate urls relative
    to a plugged application
●   tgext.pluggable.app_model provides the models of the application where the
    pluggable app will be plugged.
●   tgext.pluggable.primary_key(Model) detects the primary key of a model so
    that it is possible to create relations to models we don't know how they look
    like.
Join turbogears@googlegroups.com for more details!

More Related Content

PDF
Using Dagger in a Clean Architecture project
PPT
Struts Introduction Course
PDF
Building Large Scale Javascript Application
PPTX
Angular js 1.3 presentation for fed nov 2014
PDF
Struts2
PPTX
Built to last javascript for enterprise
PPTX
Migrating from JSF1 to JSF2
ODP
A Complete Tour of JSF 2
Using Dagger in a Clean Architecture project
Struts Introduction Course
Building Large Scale Javascript Application
Angular js 1.3 presentation for fed nov 2014
Struts2
Built to last javascript for enterprise
Migrating from JSF1 to JSF2
A Complete Tour of JSF 2

What's hot (20)

PPTX
AngularJs (1.x) Presentation
PDF
Testdrive AngularJS with Spring 4
PPT
What's new and exciting with JSF 2.0
PDF
android design pattern
PPT
Java Server Faces (JSF) - advanced
PPT
JSF Component Behaviors
DOCX
Different way to share data between controllers in angular js
PDF
Introduction of angular js
PPTX
Angular JS - Introduction
PPT
JSF Custom Components
PPTX
Introduction to Angularjs
PPT
Angular 8
PDF
Building richwebapplicationsusingasp
PDF
Jsf intro
PDF
Advance RCP
PDF
AngularJS - dependency injection
PPTX
Mean stack Magics
PDF
AngularJS in practice
PDF
Java server faces
PPT
Strutsjspservlet
AngularJs (1.x) Presentation
Testdrive AngularJS with Spring 4
What's new and exciting with JSF 2.0
android design pattern
Java Server Faces (JSF) - advanced
JSF Component Behaviors
Different way to share data between controllers in angular js
Introduction of angular js
Angular JS - Introduction
JSF Custom Components
Introduction to Angularjs
Angular 8
Building richwebapplicationsusingasp
Jsf intro
Advance RCP
AngularJS - dependency injection
Mean stack Magics
AngularJS in practice
Java server faces
Strutsjspservlet
Ad

Similar to Rapid Prototyping with TurboGears2 (20)

PDF
Introduction to django framework
PPTX
DOCX
Company Visitor Management System Report.docx
PPTX
Basic Python Django
PDF
بررسی چارچوب جنگو
PDF
Introduction to Angular Js
PDF
AngularJS Project Setup step-by- step guide - RapidValue Solutions
PDF
Advanced Dagger talk from 360andev
ODP
TangoWithDjango - ch8
PDF
How to Implement Micro Frontend Architecture using Angular Framework
PPTX
Ultimate Guide to Microservice Architecture on Kubernetes
ODP
Drools & jBPM Info Sheet
PPTX
React django
PPTX
Web worker in your angular application
PPTX
Android crash course
DOCX
Codeigniter
PPT
Introduction To Eclipse RCP
ODP
Angular js-crash-course
PPTX
Front end development with Angular JS
Introduction to django framework
Company Visitor Management System Report.docx
Basic Python Django
بررسی چارچوب جنگو
Introduction to Angular Js
AngularJS Project Setup step-by- step guide - RapidValue Solutions
Advanced Dagger talk from 360andev
TangoWithDjango - ch8
How to Implement Micro Frontend Architecture using Angular Framework
Ultimate Guide to Microservice Architecture on Kubernetes
Drools & jBPM Info Sheet
React django
Web worker in your angular application
Android crash course
Codeigniter
Introduction To Eclipse RCP
Angular js-crash-course
Front end development with Angular JS
Ad

More from Alessandro Molina (17)

PDF
PyCon Ireland 2022 - PyArrow full stack.pdf
PDF
PyconIE 2016 - Kajiki, the fast and validated template engine your were looki...
PDF
EP2016 - Moving Away From Nodejs To A Pure Python Solution For Assets
PDF
EuroPython 2015 - Storing files for the web is not as straightforward as you ...
PDF
PyConIT6 - MAKING SESSIONS AND CACHING ROOMMATES
PDF
PyConIT6 - Messing up with pymongo for fun and profit
PDF
PyConFR 2014 - DEPOT, Story of a file.write() gone wrong
PDF
PyConUK 2014 - PostMortem Debugging and Web Development Updated
PDF
Reactive & Realtime Web Applications with TurboGears2
PDF
Post-Mortem Debugging and Web Development
PDF
MongoTorino 2013 - BSON Mad Science for fun and profit
PDF
PyConUK2013 - Validated documents on MongoDB with Ming
PDF
EuroPython 2013 - FAST, DOCUMENTED AND RELIABLE JSON BASED WEBSERVICES WITH P...
PDF
EuroPython 2013 - Python3 TurboGears Training
PDF
PyGrunn2013 High Performance Web Applications with TurboGears
PDF
TurboGears2 Pluggable Applications
PDF
From SQLAlchemy to Ming with TurboGears2
PyCon Ireland 2022 - PyArrow full stack.pdf
PyconIE 2016 - Kajiki, the fast and validated template engine your were looki...
EP2016 - Moving Away From Nodejs To A Pure Python Solution For Assets
EuroPython 2015 - Storing files for the web is not as straightforward as you ...
PyConIT6 - MAKING SESSIONS AND CACHING ROOMMATES
PyConIT6 - Messing up with pymongo for fun and profit
PyConFR 2014 - DEPOT, Story of a file.write() gone wrong
PyConUK 2014 - PostMortem Debugging and Web Development Updated
Reactive & Realtime Web Applications with TurboGears2
Post-Mortem Debugging and Web Development
MongoTorino 2013 - BSON Mad Science for fun and profit
PyConUK2013 - Validated documents on MongoDB with Ming
EuroPython 2013 - FAST, DOCUMENTED AND RELIABLE JSON BASED WEBSERVICES WITH P...
EuroPython 2013 - Python3 TurboGears Training
PyGrunn2013 High Performance Web Applications with TurboGears
TurboGears2 Pluggable Applications
From SQLAlchemy to Ming with TurboGears2

Recently uploaded (20)

PDF
How IoT Sensor Integration in 2025 is Transforming Industries Worldwide
PPT
Galois Field Theory of Risk: A Perspective, Protocol, and Mathematical Backgr...
DOCX
Basics of Cloud Computing - Cloud Ecosystem
PDF
UiPath Agentic Automation session 1: RPA to Agents
PDF
Flame analysis and combustion estimation using large language and vision assi...
PPTX
The various Industrial Revolutions .pptx
PDF
Hybrid horned lizard optimization algorithm-aquila optimizer for DC motor
PDF
CloudStack 4.21: First Look Webinar slides
PPT
Geologic Time for studying geology for geologist
PDF
“A New Era of 3D Sensing: Transforming Industries and Creating Opportunities,...
PPT
What is a Computer? Input Devices /output devices
PDF
A contest of sentiment analysis: k-nearest neighbor versus neural network
PDF
sustainability-14-14877-v2.pddhzftheheeeee
PDF
How ambidextrous entrepreneurial leaders react to the artificial intelligence...
PPTX
Custom Battery Pack Design Considerations for Performance and Safety
PDF
STKI Israel Market Study 2025 version august
PDF
OpenACC and Open Hackathons Monthly Highlights July 2025
PDF
Comparative analysis of machine learning models for fake news detection in so...
PPTX
Final SEM Unit 1 for mit wpu at pune .pptx
PPT
Module 1.ppt Iot fundamentals and Architecture
How IoT Sensor Integration in 2025 is Transforming Industries Worldwide
Galois Field Theory of Risk: A Perspective, Protocol, and Mathematical Backgr...
Basics of Cloud Computing - Cloud Ecosystem
UiPath Agentic Automation session 1: RPA to Agents
Flame analysis and combustion estimation using large language and vision assi...
The various Industrial Revolutions .pptx
Hybrid horned lizard optimization algorithm-aquila optimizer for DC motor
CloudStack 4.21: First Look Webinar slides
Geologic Time for studying geology for geologist
“A New Era of 3D Sensing: Transforming Industries and Creating Opportunities,...
What is a Computer? Input Devices /output devices
A contest of sentiment analysis: k-nearest neighbor versus neural network
sustainability-14-14877-v2.pddhzftheheeeee
How ambidextrous entrepreneurial leaders react to the artificial intelligence...
Custom Battery Pack Design Considerations for Performance and Safety
STKI Israel Market Study 2025 version august
OpenACC and Open Hackathons Monthly Highlights July 2025
Comparative analysis of machine learning models for fake news detection in so...
Final SEM Unit 1 for mit wpu at pune .pptx
Module 1.ppt Iot fundamentals and Architecture

Rapid Prototyping with TurboGears2

  • 1. TurboGears2 Building Full Featured Web Applications with TurboGears2 in a bunch of minutes Alessandro Molina - @__amol__ - [email protected]
  • 2. TurboGears2 ● Framework for rapid development encouraging customization ● Object Dispatch based. Regular expressions can get messy, never write a regex anymore ● By default an XML template engine with error detection ● Declarative Models with transactional unit of work ● Built in Validation, Authentication, Authorization, Caching, Sessions, Migrations, MongoDB Support and many more.
  • 3. Looking at the code Serving /movie/3 as a webpage and /movie/3.json as a json encoded response class RootController(BaseController): @expose('myproj.templates.movie') @expose('json') @validate({'movie':SQLAEntityConverter(model.Movie)} def movie(self, movie, **kw): return dict(movie=movie, user=request.identity and request.identity['user'])
  • 5. TurboGears for RAD ● 2.0 had sprox and tgext.crud: Flexible, but hard to use! ● 2.1 had many sprox improvements and added the EasyCrudRestController ● 2.1.4 had many hooks improvements that made tgext. pluggable possible! With EasyCrudRestController and pluggable applications rapid prototyping can be rapid for real
  • 6. EasyCrudRestController Aims at making possible to create full administrative interfaces in a bunch of seconds
  • 7. Easy CRUD Minimal setup is minimal for real! from tgext.crud import EasyCrudRestController class GalleriesController(EasyCrudRestController): model = model.Gallery This provides CRUD interface with Search, ordering and autogenerated JSON Rest API for that model.
  • 8. Custom CRUD Customizing the Crud Controller can be done from the __form_options__ and __table_options__ variables of the class. class PhotosController(EasyCrudRestController): model = model.Photo allow_only = predicates.in_group('photos') title = "Manage Photos" keep_params = ['gallery'] __form_options__ = { '__hide_fields__' : ['uid', 'author', 'gallery'], '__field_widget_types__' : {'image':FileField}, '__field_validator_types__' : {'image':FieldStorageUploadConverter}, '__field_widget_args__' : {'author':{'default':lambda:request.identity['user'].user_id}} } __table_options__ = { '__omit_fields__' : ['uid', 'author_id', 'gallery_id', 'gallery'], '__xml_fields__' : ['image'], 'image': lambda filler,row: html.literal('‹img src="%s"/›' % row.image.thumb_url) }
  • 9. Custom CRUD Result Result is a web page to upload photos to a gallery with uploaded image preview
  • 10. Let's plug them all CRUD tools provide a quick and easy way to prototype new functions. But... there are things which are not a plain CRUD, how can you speed up their development? Fastest solution is to have things already done by someone else! That's what pluggable applications are for
  • 11. Pluggables Pluggable applications provide ready made features that can be plugged into your applications. ● Implemented as tgext.pluggable, if you don't use them they won't bother you ● As easy as plug(base_config, 'appname') ● They look a lot like a plain application and provide models, controllers, templates, helpers, partials, database bootstrap and so on. ● Creating one as easy as paster quickstart-pluggable appname ● Sadly supported only for SQLAlchemy storage backed, mongodb planned
  • 12. Available Pluggables tgapp-registration tgapp-smallpress Provides a registration Provides multblog with process with activation WYSIWYG editor, email. It's heavily tagcloud, attachments, customizable using drafts, future hooks. publications and Whoosh based search. tgapp-fbauth tgapp-photos facebook authentication, Provides partials to registration and display photos and connection to existing photo galleries with accounts. automatic thumbnails.
  • 13. Available Pluggables tgapp-userprofile libacr Provides a basic profile Provides a powerful page and badge CMS where pages for users with profile are splitted into slices picture took from each editable facebook, gravatar or and of its own type. custom source. Custom slices and new type of contents stroller can be easily created directly from the CMS Provides eCommerce itself without editing application with code. categories, multiple pictures for each product and orders management.
  • 14. DebugBar To improve developers life the first pluggable application created has been the debugbar. ● Controller methods profiling ● Template Rendering timings ● Query inspector ● Request inspector ● and so on... The usual things you would expect from a debug bar!
  • 15. Inventing Mode How the debugbar relates to rapid prototyping? Well, it makes life easier, but mostly... It provides the inventing mode! Place your browser and code editor side by side and start experimenting, your changes will reflect into the browser in real time and it will notify you when you broke something.
  • 16. Creating pluggables Once tgext.pluggable gets installed the quickstart-pluggable command becames available. Running quickstart-pluggable will create a package that looks a lot like a TurboGears application but provides a plugme method inside its __init__.py plugme method is the entry point of your pluggable application. def plugme(app_config, options): return dict(appid='plugtest', global_helpers=False)
  • 17. Structure of a Pluggable $ paster quickstart-pluggable plugtest Pluggable Applications controllers, root controller of the application is named RootController inside the root.py file and will be mounted as /plugtest Models of the pluggable applications, will be bound to the session of the master app Static files of the pluggable application, will be available at /_pluggable/plugtest Templates of the pluggable application, controllers can use them with standard expose syntax: @expose('plugtest. templates.index')
  • 18. Structure of a Pluggable Here rely all the utility functions of the pluggable application. By default they are not exposed to the master application but are stille accessible as a python module bootstrap is automatically called when initializing the database of the master application. Pluggables can provide helpers which will be automatically available into the master application as h.plugtest.helpername Partials are evolved helpers, they provide logic and look like controllers with an exposed template. They are acceissible inside templates with h.call_partial('plugtest.partials: partialname')
  • 19. Pluggable Utilities tgext.pluggable provides a bunch of utilities that help when working with pluggable applications to override part of their aspect or behavior: ● replace_template(base_config, 'otherapp.templates.about', 'myapp. templates.index') permits to replace any template with another one, makes possible to change the look of any plugged web page ● plug_url('plugtest', '/somewhere') makes possible to generate urls relative to a plugged application ● tgext.pluggable.app_model provides the models of the application where the pluggable app will be plugged. ● tgext.pluggable.primary_key(Model) detects the primary key of a model so that it is possible to create relations to models we don't know how they look like.