David Glick: Building Content Types with Dexterity
By David Glick, ONE/Northwest, USA
Over the past year and a half, Martin Aspeli and company have been hard at work creating Dexterity, the next-generation framework for developing content types in Plone. In this tutorial, you learn the basics of building content types with Dexterity, how it compares to Archetypes, and the current status of the project.
I am working for groundwire, formerly known as ONe/Northwest.
A content type is for example a page, document or image. It has a schema, custom view templates, miscelaneous settings (can you search for it, can you add comments, etc).
History lesson. CMF (Content Management Framework) is an underlying framework for registering types, assigning workflows. Not schema based. Archetypes came along and provided schemas, with schema based form generation. Not going away anytime soon. But it has some ugly bits. Not easy as basis for generating schemas TTW (through the web).
At the Plone Planning Summit we talked about how we were going to create content types in the future, still archetypes or not. So after that, Martin Aspeli started the Dexterity project. Make it possible to define a content type through the web, export it to the file system and be able to do this the other way around as well.
Products.Archetypes is big. plone.dexterity is small and you can extend it with just the extra parts you need.
Archetypes does a lot of what seems to be magic; a lot of code, like factories and methods, that are created on the fly.
Installing dexterity: add the plone.app.dexterity egg in your buildout.cfg and add http://good-py.appspot.com/release/dexterity/1.0a2 in your buildout extends lines.
Options for extending a content type are subclassing, archetypes.schemaextender, and now with dexterity you have a new concept called behaviors. A behavior can be something like: create the short name of the object from the title; add geolocation; add ownership.
You have to watch out when changing a content type, as existing objects are not automatically updated, for instance when you change a field name.
We don't create custom Add permissions yet through the web.
Example package: example.ploneconf09 at http://svn.plone.org/svn/plone//plone.dexterity/example.ploneconf09
The type definition can just be exported via portal_setup by exporting the types tool. We want some new UI for this. The schema will be in there, in escaped xml. You can also put this in a separate xml file, or define a zope 3 schema--use plone.directives.form for this.
Using a zope 3 schema: add five.grok as dependency and add <grok:grok package="." /> to your zcml. To move a field to a different fieldset, specify form.fieldset in the schema and list the fields you want to have on this tab.
With plone.directives.dexterity you can define read and write permissions.
- plone.dexterity: base content class
- plone.autoform: makes it possible for a form to be composed by scheas and form hints from different sources, like base schema and behavior schema.
- plone.schemaeditor: UI for editing zope 3 interfaces TTW. Dexterity integrates this with its types control panel
- plone.supermodel: translates zope 3 schema into xml and the other way around. Easily extensible.
- plone.directives.dexterity: Grok directives for custom views and content classes.
- plone.folder: orderable Btree based folder implementation, will be used in Plone 4 as well.
- plone.behavior: register behaviors (conditional adapters). For dexterity the condition is whether the behavior is checked in the FTI.
- plone.rfc822: supports marshalling dexterity content into rfc822 (email) format.
- plone.app.dexterity: pulls in everything you need. Has the standard behaviors.
- The core functionality is pretty solid.
- Schema serialization has a few issues, but works okay.
- Automatic form generation works fine.
- You can assign content rules to dexterity.
- Relations: not working between archetypes and dexterity content in the same site.
- Widgets are not as rich as archetypes yet, but better than formlib.
- TTW schema editing works fine, but needs more real-life use to iron out any bugs.
- Image and file support are done via plone.namedfile and plone.formwidget.namedfile; no support for image scaling yet, unlike archetypes.
- Text transform support via plone.app.textfield.
- Select field support; no way to define vocabularies TTW yet.
- Support for versioning and staging is in progress.
- No automatic migration from archetypes to dexterity yet.
- Multilingual: no support yet.
Second alpha release was on October 12th 2009. First beta coming soon.
Works on Plone 3. Support for Plone 4 coming soon.
Performance benchmarks are mostly better than archetypes, except the view, but I take that with a grain of salt. Loading an Add form is much faster.
Manuals here: http://plone.org/products/dexterity/documentation/manual
Get involved, code: http://code.google.com/p/dexterity/
google group: http://groups.google.com/group/dexterity-development
Dexterity objects are smaller than archetypes objects in the zodb.
See the slides.