SlideShare a Scribd company logo
1 of 5
Download to read offline
Deform: A Form Generation System                              file:///Users/aclark/Desktop/zpugdc-deformpresentation/slides.html




                      Deform: A Form Generation System

                    Authors:       Chris McDonough
                                   Agendaless Consulting
                    Date:          7/6/2010




         Features
               Generates forms which are capable of capturing complex data structures (lists and mappings,
               recursively).
               Form validation and errors
               AJAX (actually AJAH) forms
               Client side field filters (masks for SSN, etc)
               Widgets for most common tasks


         Comparable To
               z3c.form
               zope.formlib
               ToscaWidgets
               Django newforms
               Formish (heavily influenced by)
               WTForm


         Superset Of
               Formencode


         Notables
               Deform not concerned with "model" data. Only with "form" data. The schema you use in
               Deform is unrelated to your model's schema.
               Compatible with any web framework (or non-framework). No assumptions made about
               request/response library, etc.


1 of 5                                                                                                         7/9/10 9:21 PM
Deform: A Form Generation System                                 file:///Users/aclark/Desktop/zpugdc-deformpresentation/slides.html



         Process
               100% statement coverage via unit tests
               Each widget has a functional selenium test that uses the application at
               http://deformdemo.repoze.org as the application under test.
               Well-documented at http://docs.repoze.org/deform.


         Dependencies
               Colander schema library
               Peppercorn form marshalling library
               Chameleon templating library
               Translationstring i18n library
               ISO8601 date parsing library


         Generating a Form
         This will generate a form with a single text input widget:

              import colander, deform
              class Schema(colander.Schema):
                  text = colander.SchemaNode(
                      colander.String(),
                      validator=colander.Length(max=100),
                      description='Enter some text')
              schema = Schema()
              form = deform.Form(schema, buttons=('submit',))
              html = form.render()


         Schema Nodes
         Schema nodes in a schema can provide:

               Its type (string, int, mapping, etc).
               A validator function.
               The initial value and the "missing" value.
               A name, a title, and a description, used during rendering.
               Schema nodes are the domain of the Colander package.


         Widgets

2 of 5                                                                                                            7/9/10 9:21 PM
Deform: A Form Generation System                                  file:///Users/aclark/Desktop/zpugdc-deformpresentation/slides.html


               Many prebaked widgets.
               1-to-1 relationship between widget and schema node.
               Widgets are written in a combination of Python and the Chameleon ZPT templating language
               Any other templating language may be used; hook points exist to use a new one.
               Different widgets may be used for the same type of schema field (e.g. checkbox vs. radio
               choice).
               Widgets can be created as necessary.
               Widgets are the domain of the Deform package.


         Widget Template Example
         Here's an example of a widget template that uses Chameleon:

              <textarea tal:attributes="rows field.widget.rows;
                                        cols field.widget.cols;"
                        id="${field.oid}"
                        name="${field.name}">${cstruct}</textarea>


         Validators
               Deform ships with a number of prebaked validators for common cases (length, one-of, email-
               address, in-range, etc).
               New validators can be added.
               Validators are the domain of both the Colander and Deform packages.


         Validator Example
         An example of a Deform validator (return value unimportant):

              def is_int(node, value):
                  try:
                       int(value)
                  except (ValueError, OverflowError, TypeError):
                       raise Invalid(node,
                                     '%r is not a valid integer' %
                                     value)


         Edit Forms
         Forms allowing you to edit existing data are similar; you just pass in the data structure you'd like to
         edit (it must match the schema):



3 of 5                                                                                                             7/9/10 9:21 PM
Deform: A Form Generation System                                file:///Users/aclark/Desktop/zpugdc-deformpresentation/slides.html


              import colander, deform
              class Schema(colander.Schema):
                  text = colander.SchemaNode(
                      colander.String(),
                      validator=colander.Length(max=100),
                      description='Enter some text')
              schema = Schema()
              form = deform.Form(schema, buttons=('submit',))
              html = form.render({'text':'Hello!'})


         Validation and Re-Rendering
         Your code is in charge of doing validation and re-rendering:

              # form = deform.Form(schema, buttons=('submit',))
              try:
                   controls = self.request.POST.items()
                   captured = form.validate(controls)
                   html = form.render(captured)
              except deform.ValidationFailure, e:
                   # the submitted values could not be validated
                   html = e.render()


         Editing Structure
         Often we need to edit or add structure:

               "Multi-file" upload widget
               Multiple people in a list

         Let's see some of that live.


         Miscellaneous Features
               Internationalization: Deform error messages are internationalizable.
               Multiple Forms on the Same Page: possible.
               Inter-field Validation: Validator attached to a container node.
               AJAX Forms: Built-in.
               Input Masks: Built-in.


         Futures
               Deform is "done".


4 of 5                                                                                                           7/9/10 9:21 PM
Deform: A Form Generation System                            file:///Users/aclark/Desktop/zpugdc-deformpresentation/slides.html


               Systems are being built atop Deform (e.g. a "CRUD" system which conflates the model schema
               with the form schema).


         End
               Get it via easy_install deform
               Docs at http://docs.repoze.org/deform




5 of 5                                                                                                       7/9/10 9:21 PM

More Related Content

Similar to Generate Complex Forms with Deform

Choose'10: Ralf Laemmel - Dealing Confortably with the Confusion of Tongues
Choose'10: Ralf Laemmel - Dealing Confortably with the Confusion of TonguesChoose'10: Ralf Laemmel - Dealing Confortably with the Confusion of Tongues
Choose'10: Ralf Laemmel - Dealing Confortably with the Confusion of TonguesCHOOSE
 
Phoenix for Rails Devs
Phoenix for Rails DevsPhoenix for Rails Devs
Phoenix for Rails DevsDiacode
 
The Theory Of The Dom
The Theory Of The DomThe Theory Of The Dom
The Theory Of The Domkaven yan
 
Eclipse World 2007: Fundamentals of the Eclipse Modeling Framework
Eclipse World 2007: Fundamentals of the Eclipse Modeling FrameworkEclipse World 2007: Fundamentals of the Eclipse Modeling Framework
Eclipse World 2007: Fundamentals of the Eclipse Modeling FrameworkDave Steinberg
 
Angular JS2 Training Session #1
Angular JS2 Training Session #1Angular JS2 Training Session #1
Angular JS2 Training Session #1Paras Mendiratta
 
Working With The Symfony Admin Generator
Working With The Symfony Admin GeneratorWorking With The Symfony Admin Generator
Working With The Symfony Admin GeneratorJohn Cleveley
 
JavaFX programming
JavaFX programmingJavaFX programming
JavaFX programmingFulvio Corno
 
Javascript-heavy Salesforce Applications
Javascript-heavy Salesforce ApplicationsJavascript-heavy Salesforce Applications
Javascript-heavy Salesforce ApplicationsSalesforce Developers
 
Porting VisualWorks code to Pharo
Porting VisualWorks code to PharoPorting VisualWorks code to Pharo
Porting VisualWorks code to PharoESUG
 
JavaScript Miller Columns
JavaScript Miller ColumnsJavaScript Miller Columns
JavaScript Miller ColumnsJonathan Fine
 
Patterns in Python
Patterns in PythonPatterns in Python
Patterns in Pythondn
 
MCS,BCS-7(A,B) Visual programming Syllabus for Final exams @ ISP
MCS,BCS-7(A,B) Visual programming Syllabus for Final exams @ ISPMCS,BCS-7(A,B) Visual programming Syllabus for Final exams @ ISP
MCS,BCS-7(A,B) Visual programming Syllabus for Final exams @ ISPAli Shah
 
Using SPMetal for faster SharePoint development
Using SPMetal for faster SharePoint developmentUsing SPMetal for faster SharePoint development
Using SPMetal for faster SharePoint developmentPranav Sharma
 
Session on Selenium Powertools by Unmesh Gundecha
Session on Selenium Powertools by Unmesh GundechaSession on Selenium Powertools by Unmesh Gundecha
Session on Selenium Powertools by Unmesh GundechaAgile Testing Alliance
 
Example Cosmos SDK Application Tutorial
Example Cosmos SDK Application TutorialExample Cosmos SDK Application Tutorial
Example Cosmos SDK Application TutorialJim Yang
 
Workshop 23: ReactJS, React & Redux testing
Workshop 23: ReactJS, React & Redux testingWorkshop 23: ReactJS, React & Redux testing
Workshop 23: ReactJS, React & Redux testingVisual Engineering
 
Spring 3: What's New
Spring 3: What's NewSpring 3: What's New
Spring 3: What's NewTed Pennings
 

Similar to Generate Complex Forms with Deform (20)

Choose'10: Ralf Laemmel - Dealing Confortably with the Confusion of Tongues
Choose'10: Ralf Laemmel - Dealing Confortably with the Confusion of TonguesChoose'10: Ralf Laemmel - Dealing Confortably with the Confusion of Tongues
Choose'10: Ralf Laemmel - Dealing Confortably with the Confusion of Tongues
 
Phoenix for Rails Devs
Phoenix for Rails DevsPhoenix for Rails Devs
Phoenix for Rails Devs
 
The Theory Of The Dom
The Theory Of The DomThe Theory Of The Dom
The Theory Of The Dom
 
Eclipse World 2007: Fundamentals of the Eclipse Modeling Framework
Eclipse World 2007: Fundamentals of the Eclipse Modeling FrameworkEclipse World 2007: Fundamentals of the Eclipse Modeling Framework
Eclipse World 2007: Fundamentals of the Eclipse Modeling Framework
 
IOC + Javascript
IOC + JavascriptIOC + Javascript
IOC + Javascript
 
Angular JS2 Training Session #1
Angular JS2 Training Session #1Angular JS2 Training Session #1
Angular JS2 Training Session #1
 
Working With The Symfony Admin Generator
Working With The Symfony Admin GeneratorWorking With The Symfony Admin Generator
Working With The Symfony Admin Generator
 
JavaFX programming
JavaFX programmingJavaFX programming
JavaFX programming
 
Javascript-heavy Salesforce Applications
Javascript-heavy Salesforce ApplicationsJavascript-heavy Salesforce Applications
Javascript-heavy Salesforce Applications
 
Porting VisualWorks code to Pharo
Porting VisualWorks code to PharoPorting VisualWorks code to Pharo
Porting VisualWorks code to Pharo
 
JavaScript Miller Columns
JavaScript Miller ColumnsJavaScript Miller Columns
JavaScript Miller Columns
 
Patterns in Python
Patterns in PythonPatterns in Python
Patterns in Python
 
MCS,BCS-7(A,B) Visual programming Syllabus for Final exams @ ISP
MCS,BCS-7(A,B) Visual programming Syllabus for Final exams @ ISPMCS,BCS-7(A,B) Visual programming Syllabus for Final exams @ ISP
MCS,BCS-7(A,B) Visual programming Syllabus for Final exams @ ISP
 
Using SPMetal for faster SharePoint development
Using SPMetal for faster SharePoint developmentUsing SPMetal for faster SharePoint development
Using SPMetal for faster SharePoint development
 
Adobe Flex4
Adobe Flex4 Adobe Flex4
Adobe Flex4
 
Session on Selenium Powertools by Unmesh Gundecha
Session on Selenium Powertools by Unmesh GundechaSession on Selenium Powertools by Unmesh Gundecha
Session on Selenium Powertools by Unmesh Gundecha
 
Example Cosmos SDK Application Tutorial
Example Cosmos SDK Application TutorialExample Cosmos SDK Application Tutorial
Example Cosmos SDK Application Tutorial
 
Workshop 23: ReactJS, React & Redux testing
Workshop 23: ReactJS, React & Redux testingWorkshop 23: ReactJS, React & Redux testing
Workshop 23: ReactJS, React & Redux testing
 
Spring 3: What's New
Spring 3: What's NewSpring 3: What's New
Spring 3: What's New
 
Workshop 17: EmberJS parte II
Workshop 17: EmberJS parte IIWorkshop 17: EmberJS parte II
Workshop 17: EmberJS parte II
 

More from Jeffrey Clark

Python memory management_v2
Python memory management_v2Python memory management_v2
Python memory management_v2Jeffrey Clark
 
Jwt with flask slide deck - alan swenson
Jwt with flask   slide deck - alan swensonJwt with flask   slide deck - alan swenson
Jwt with flask slide deck - alan swensonJeffrey Clark
 
Genericmeetupslides 110607190400-phpapp02
Genericmeetupslides 110607190400-phpapp02Genericmeetupslides 110607190400-phpapp02
Genericmeetupslides 110607190400-phpapp02Jeffrey Clark
 
Pyramiddcpythonfeb2013 131006105131-phpapp02
Pyramiddcpythonfeb2013 131006105131-phpapp02Pyramiddcpythonfeb2013 131006105131-phpapp02
Pyramiddcpythonfeb2013 131006105131-phpapp02Jeffrey Clark
 
Zpugdc2007 101105081808-phpapp01
Zpugdc2007 101105081808-phpapp01Zpugdc2007 101105081808-phpapp01
Zpugdc2007 101105081808-phpapp01Jeffrey Clark
 
Zpugdccherry 101105081729-phpapp01
Zpugdccherry 101105081729-phpapp01Zpugdccherry 101105081729-phpapp01
Zpugdccherry 101105081729-phpapp01Jeffrey Clark
 
Using Grok to Walk Like a Duck - Brandon Craig Rhodes
Using Grok to Walk Like a Duck - Brandon Craig RhodesUsing Grok to Walk Like a Duck - Brandon Craig Rhodes
Using Grok to Walk Like a Duck - Brandon Craig RhodesJeffrey Clark
 
What Makes A Great Dev Team - Mike Robinson
What Makes A Great Dev Team - Mike RobinsonWhat Makes A Great Dev Team - Mike Robinson
What Makes A Great Dev Team - Mike RobinsonJeffrey Clark
 
What Makes A Great Dev Team - Mike Robinson
What Makes A Great Dev Team - Mike RobinsonWhat Makes A Great Dev Team - Mike Robinson
What Makes A Great Dev Team - Mike RobinsonJeffrey Clark
 
Plone I18n Tutorial - Hanno Schlichting
Plone I18n Tutorial - Hanno SchlichtingPlone I18n Tutorial - Hanno Schlichting
Plone I18n Tutorial - Hanno SchlichtingJeffrey Clark
 
State Of Zope 3 - Stephan Richter
State Of Zope 3 - Stephan RichterState Of Zope 3 - Stephan Richter
State Of Zope 3 - Stephan RichterJeffrey Clark
 
KSS Techniques - Joel Burton
KSS Techniques - Joel BurtonKSS Techniques - Joel Burton
KSS Techniques - Joel BurtonJeffrey Clark
 
Bfg Ploneconf Oct2008
Bfg Ploneconf Oct2008Bfg Ploneconf Oct2008
Bfg Ploneconf Oct2008Jeffrey Clark
 

More from Jeffrey Clark (20)

Python memory management_v2
Python memory management_v2Python memory management_v2
Python memory management_v2
 
Python meetup
Python meetupPython meetup
Python meetup
 
Jwt with flask slide deck - alan swenson
Jwt with flask   slide deck - alan swensonJwt with flask   slide deck - alan swenson
Jwt with flask slide deck - alan swenson
 
Genericmeetupslides 110607190400-phpapp02
Genericmeetupslides 110607190400-phpapp02Genericmeetupslides 110607190400-phpapp02
Genericmeetupslides 110607190400-phpapp02
 
Pyramiddcpythonfeb2013 131006105131-phpapp02
Pyramiddcpythonfeb2013 131006105131-phpapp02Pyramiddcpythonfeb2013 131006105131-phpapp02
Pyramiddcpythonfeb2013 131006105131-phpapp02
 
Dc python meetup
Dc python meetupDc python meetup
Dc python meetup
 
Zpugdc2007 101105081808-phpapp01
Zpugdc2007 101105081808-phpapp01Zpugdc2007 101105081808-phpapp01
Zpugdc2007 101105081808-phpapp01
 
Zpugdccherry 101105081729-phpapp01
Zpugdccherry 101105081729-phpapp01Zpugdccherry 101105081729-phpapp01
Zpugdccherry 101105081729-phpapp01
 
Tornado
TornadoTornado
Tornado
 
The PSF and You
The PSF and YouThe PSF and You
The PSF and You
 
Using Grok to Walk Like a Duck - Brandon Craig Rhodes
Using Grok to Walk Like a Duck - Brandon Craig RhodesUsing Grok to Walk Like a Duck - Brandon Craig Rhodes
Using Grok to Walk Like a Duck - Brandon Craig Rhodes
 
What Makes A Great Dev Team - Mike Robinson
What Makes A Great Dev Team - Mike RobinsonWhat Makes A Great Dev Team - Mike Robinson
What Makes A Great Dev Team - Mike Robinson
 
What Makes A Great Dev Team - Mike Robinson
What Makes A Great Dev Team - Mike RobinsonWhat Makes A Great Dev Team - Mike Robinson
What Makes A Great Dev Team - Mike Robinson
 
Plone I18n Tutorial - Hanno Schlichting
Plone I18n Tutorial - Hanno SchlichtingPlone I18n Tutorial - Hanno Schlichting
Plone I18n Tutorial - Hanno Schlichting
 
State Of Zope 3 - Stephan Richter
State Of Zope 3 - Stephan RichterState Of Zope 3 - Stephan Richter
State Of Zope 3 - Stephan Richter
 
KSS Techniques - Joel Burton
KSS Techniques - Joel BurtonKSS Techniques - Joel Burton
KSS Techniques - Joel Burton
 
Zenoss: Buildout
Zenoss: BuildoutZenoss: Buildout
Zenoss: Buildout
 
Opensourceweblion
OpensourceweblionOpensourceweblion
Opensourceweblion
 
Simplifying Plone
Simplifying PloneSimplifying Plone
Simplifying Plone
 
Bfg Ploneconf Oct2008
Bfg Ploneconf Oct2008Bfg Ploneconf Oct2008
Bfg Ploneconf Oct2008
 

Generate Complex Forms with Deform

  • 1. Deform: A Form Generation System file:///Users/aclark/Desktop/zpugdc-deformpresentation/slides.html Deform: A Form Generation System Authors: Chris McDonough Agendaless Consulting Date: 7/6/2010 Features Generates forms which are capable of capturing complex data structures (lists and mappings, recursively). Form validation and errors AJAX (actually AJAH) forms Client side field filters (masks for SSN, etc) Widgets for most common tasks Comparable To z3c.form zope.formlib ToscaWidgets Django newforms Formish (heavily influenced by) WTForm Superset Of Formencode Notables Deform not concerned with "model" data. Only with "form" data. The schema you use in Deform is unrelated to your model's schema. Compatible with any web framework (or non-framework). No assumptions made about request/response library, etc. 1 of 5 7/9/10 9:21 PM
  • 2. Deform: A Form Generation System file:///Users/aclark/Desktop/zpugdc-deformpresentation/slides.html Process 100% statement coverage via unit tests Each widget has a functional selenium test that uses the application at http://deformdemo.repoze.org as the application under test. Well-documented at http://docs.repoze.org/deform. Dependencies Colander schema library Peppercorn form marshalling library Chameleon templating library Translationstring i18n library ISO8601 date parsing library Generating a Form This will generate a form with a single text input widget: import colander, deform class Schema(colander.Schema): text = colander.SchemaNode( colander.String(), validator=colander.Length(max=100), description='Enter some text') schema = Schema() form = deform.Form(schema, buttons=('submit',)) html = form.render() Schema Nodes Schema nodes in a schema can provide: Its type (string, int, mapping, etc). A validator function. The initial value and the "missing" value. A name, a title, and a description, used during rendering. Schema nodes are the domain of the Colander package. Widgets 2 of 5 7/9/10 9:21 PM
  • 3. Deform: A Form Generation System file:///Users/aclark/Desktop/zpugdc-deformpresentation/slides.html Many prebaked widgets. 1-to-1 relationship between widget and schema node. Widgets are written in a combination of Python and the Chameleon ZPT templating language Any other templating language may be used; hook points exist to use a new one. Different widgets may be used for the same type of schema field (e.g. checkbox vs. radio choice). Widgets can be created as necessary. Widgets are the domain of the Deform package. Widget Template Example Here's an example of a widget template that uses Chameleon: <textarea tal:attributes="rows field.widget.rows; cols field.widget.cols;" id="${field.oid}" name="${field.name}">${cstruct}</textarea> Validators Deform ships with a number of prebaked validators for common cases (length, one-of, email- address, in-range, etc). New validators can be added. Validators are the domain of both the Colander and Deform packages. Validator Example An example of a Deform validator (return value unimportant): def is_int(node, value): try: int(value) except (ValueError, OverflowError, TypeError): raise Invalid(node, '%r is not a valid integer' % value) Edit Forms Forms allowing you to edit existing data are similar; you just pass in the data structure you'd like to edit (it must match the schema): 3 of 5 7/9/10 9:21 PM
  • 4. Deform: A Form Generation System file:///Users/aclark/Desktop/zpugdc-deformpresentation/slides.html import colander, deform class Schema(colander.Schema): text = colander.SchemaNode( colander.String(), validator=colander.Length(max=100), description='Enter some text') schema = Schema() form = deform.Form(schema, buttons=('submit',)) html = form.render({'text':'Hello!'}) Validation and Re-Rendering Your code is in charge of doing validation and re-rendering: # form = deform.Form(schema, buttons=('submit',)) try: controls = self.request.POST.items() captured = form.validate(controls) html = form.render(captured) except deform.ValidationFailure, e: # the submitted values could not be validated html = e.render() Editing Structure Often we need to edit or add structure: "Multi-file" upload widget Multiple people in a list Let's see some of that live. Miscellaneous Features Internationalization: Deform error messages are internationalizable. Multiple Forms on the Same Page: possible. Inter-field Validation: Validator attached to a container node. AJAX Forms: Built-in. Input Masks: Built-in. Futures Deform is "done". 4 of 5 7/9/10 9:21 PM
  • 5. Deform: A Form Generation System file:///Users/aclark/Desktop/zpugdc-deformpresentation/slides.html Systems are being built atop Deform (e.g. a "CRUD" system which conflates the model schema with the form schema). End Get it via easy_install deform Docs at http://docs.repoze.org/deform 5 of 5 7/9/10 9:21 PM