Skip to content. | Skip to navigation

Personal tools

Navigation

You are here: Home / Steve's Blog / Dexterity: It's easier than you think

Dexterity: It's easier than you think

Posted by Steve McMahon at May 21, 2013 11:14 AM |
Filed under:
Dexterity offers more than one way to do it. One way is much easier for rapid development.
Dexterity: It's easier than you think

TTW Developed

Dexterity is the new content-type development system built into Plone 4.3. It's also usable with Plone 4.1 and 4.2. Lately I've been working on developing a fairly sophisticated content type with Dexterity. It has fieldsets, smart validation and real vocabularies.

All these features were developed through the web. This meant that I was able to show them to project stakeholders — and even do some light usability testing — before ever turning the project into an add-on package. And, when I did convert the project into a Python package, nothing was lost.

Want more? I'll be teaching a class on Developing with Dexterity, June 3-4 at Plone Symposium Midwest.

If you've touched Dexterity at all, you've realized that you may use the TTW field editor to rapidly create a content type with a full set of fields and behaviors. You may be surprised, though, to learn that it's possible to organize the add/edit form into fieldsets, or to wire in validation and vocabularies, without moving the content type to an add-on package.

The trick is that it's possible to edit the XML representation of the field schema all the way through the TTW development process. XML edits show up immediately in your Dexterity type's field display and you may continue to add, move, delete and edit fields there:

Still TTW

If you've followed Dexterity development, you know that this is not really a trick at all: Dexterity was meant to work this way. Dexterity maintains the TTW field list as an XML representation via the supermodel package, which translates back and forth between field schemas and XML. While you're developing TTW, the editable XML representation is stored in the content type's Factory Type Information.

Documentation on how to add fieldsets, validators, vocabularies and permissions via XML is available in the recently created Dexterity XML Reference. To give you a hint of how it works, it's this easy to do a fieldset:

<schema>
  ...
  <fieldset name="test"
          label="Test Fieldset"
          description="Description of test fieldset">
      <field name="three" type="zope.schema.TextLine">
        <description/>
        <title>Three</title>
      </field>
      <field name="four" type="zope.schema.TextLine">
        <description/>
        <title>Four</title>
      </field>
  </fieldset>
  ...
</schema>

The Bad News

The gotcha is that editing the XML is currently a ZMI step. Go to portal_types, find the type, edit the XML.

The Good News

This is about to get better. The next minor release of Dexterity will have an "Edit XML Model" on the field editor:

Edit XML!

Pushing it will use Plone 4.3's new resource editor package (built on the Ace editor) to open an editor. And, not only can you edit, but on save you'll get XML syntax and Dexterity resource checking:

Dexterity resource check

When you're ready to move your project to a Python package, you may keep the XML model you've developed and continue to elaborate your fieldsets by editing that model.