This document discusses Dexterity, a content type system for Plone that provides a more Pythonic and schema-based approach compared to earlier systems like Archetypes. It covers installing and using Dexterity, including defining a sample "Plonista" content type with fields, behaviors and a custom view template. The goals and philosophy of Dexterity emphasize reuse, simplicity, and automation over excessive flexibility. Key components that Dexterity builds on are also summarized.
9. History Lesson
http://commons.wikimedia.org/wiki/File:1893_Nina_Pinta_Santa_Maria_replicas.jpg
10. Content Management
Framework (CMF)
• Underlying framework for registering
types, assigning workflow
• CMFDefault contains sample types which
used to be used by Plone
• Not schema-based
11. Archetypes
• Schema-based form generation
• Basis of Plone's current default content
types (ATContentTypes)
• Not going away anytime soon
19. Small over big
Pro duc ts .Arc he ty pe s
plone.app.dexterity
base classes
metadata plone.behavior
felds schema plone.directives.*
plone.autoform
widgets
plo ne .de x te rity
storage
plone.supermodel z3c.form
reference
engine
plone.schemaeditor
plone.app.relations
33. A few issues
• Bad short name for URL (“plonista”)
• Showing lots of metadata fields we don't
care about
• We want it to say “Name” instead of “Title”
• Doesn't store anything interesting yet :)
...so let's fix it!
34. Behaviors
s ubc la s s ing s c he m a be ha v io rs
schema e x te ns io n
ATFile schema
model
schema
schema
schema Deco thumbnail
schema
layout image
ATFile
Dexterity
versioned File name from
CustomATFile ATFile title
geolocatable
ratings
35. Editing the 'Plonista' Behaviors
Disable this to hide the metadata
Enable this to generate short
name from title
42. Rapid Prototyping
• The schema object in memory is directly
modified, so changes take effect
immediately.
• The changes are also serialized to XML and
stored in the ZODB (in a property of the
FTI), so they are persistent when Zope
restarts.
43. Modifying a Type
• You can add, remove, and rename fields
through the web.
• But, values stored in existing instances will
not be automatically removed or converted.
So be careful.
44. Some more desired refinements
• Custom add permission
• Show the 'bio' field in a separate fieldset.
…we can't do these through the web
(at least not yet)
45. Filesystem roundtripping
We b File s y s te m
Zope 3 Schema Schema as
Python interface
Content
Editing py
Schema
Editing
xml xml External
GenericSetup tools
import/export
XML schema in XML schema
FTI on flesystem
48. setup.py
setup(name='example.ploneconf09',
...
install_requires=[
'setuptools',
'plone.app.dexterity', Make sure we automatically get Dexterity
# -*- Extra requirements: -*-
],
entry_points="""
[z3c.autoinclude.plugin]
Make sure we don't need a ZCML slug
target = plone (in Plone 3.3 and greater)
""",
)
53. plonista.xml (continued)
<property name="add_permission">cmf.AddPortalContent</property>
<property name="klass">plone.dexterity.content.Item</property>
<property name="behaviors">
<element value="plone.app.content.interfaces.INameFromTitle"/>
</property>
<property name="schema"></property> Can put model in a Zope 3 schema.
<property
name="model_source"><model xmlns="http://namespaces.plone.org/supermodel/schema">
<schema>
<field name="title" type="zope.schema.TextLine">
<description />
<title>Name</title>
</field>
<field name="portrait" type="plone.namedfile.field.NamedBlobImage">
<title>Portrait</title>
</field>
<field name="bio" type="plone.app.textfield.RichText">
<title>Bio</title>
</field>
</schema>
</model></property>
<property name="model_file"></property> Can put model in a separate fle.
(These are the Dexterity-specifc bits.)
55. Custom add permission
• In configure.zcml:
<permission
id="example.ploneconf09.AddPlonista"
title="example.ploneconf09: Add plonista"
/>
• In plonista.xml:
<property name="add_permission">example.ploneconf09.AddPlonista</property>
• Add collective.autopermission dependency
in setup.py, rerun buildout
56. Using a Zope 3 schema
• In plonista.py:
from zope import schema
from plone.directives import form
from plone.namedfile.field import NamedBlobImage
from plone.app.textfield import RichText
class IPlonista(form.Schema):
title = schema.TextLine(
title = u'Name',
)
portrait = NamedBlobImage(
title = u'Portrait',
required = False,
)
bio = RichText(
title=u'Bio',
required = False,
)
57. Using a Zope 3 Schema
• In configure.zcml:
<configure
...
xmlns:grok="http://namespaces.zope.org/grok">
<grok:grok package="."/>
...
</configure>
• Add five.grok to dependencies in setup.py
• In plonista.xml:
<property name="schema">example.ploneconf09.plonista.IPlonista</property>
<property name="model_source"></property>
58. Specifying a fieldset
class IPlonista(form.Schema):
…
bio = RichText(
title=u'Bio',
required = False,
)
form.fieldset(
'bio',
label=u'Bio',
fields=['bio'],
)
59. More form directives
• widget – specify alternate widget
• omitted – omits fields
• mode – input, display, or hidden
• order_before, order_after – adjust position
67. The pieces
http://www.fickr.com/photos/intvgene/370973576/
68. five.grok
• Allows for writing configuration directives
in Python and in place, instead of using
ZCML.
• “Grok” a package using the following
ZCML, and it will register anything its
grokkers find and recognize.
<grok:grok package="." />
69. plone.dexterity
• Base content classes.
• FTI (Factory Type Information)
provides for dynamic lookup
of model and schema.
• Default edit form and view.
70. plone.autoform
• Dexterity renders widgets using z3c.form.
• Plone.autoform makes it possible for a form
to be composed by schemas and form hints
from different sources.
(Main schema + behavior schemas,
in the case of Dexterity.)
71. plone.schemaeditor
• Provides the UI for editing Zope 3
interfaces through the web.
• Dexterity integrates it with the Dexterity
types control panel, but it could be used
separately.
• IFieldFactory lookup determines what
fields can be edited.
72. plone.supermodel
• Serializer translates a Zope 3 schema into
XML.
• Parser translates an XML schema into a
Zope 3 schema.
• Easily extensible
» Field handlers found via adapter lookup
» Additional metadata handlers may handle
custom XML namespaces
73. plone.directives.form
• Defines the form rendering hint directives
that may be included in schemas for use by
plone.autoform when rendering forms and
views.
76. plone.behavior
• A behavior is a conditional adapter.
• In Dexterity, the condition is whether the
behavior is listed in the FTI for an item.
• ZCML directive for registering new
behaviors.
77. plone.rfc822
• Supports the marshalling of Dexterity
content into RFC 822 format.
• Used to support access via WebDAV.
78. plone.app.dexterity
• Pulls in everything you need.
• Standard behaviors.
» Dublin Core
» Related Items
• Dexterity types control panel.
79. Status report / roadmap
http://www.fickr.com/photos/brianatwebbmoto/2392041992/sizes/m/
100. Further information
• Dexterity manual:
http://plone.org/products/dexterity/docu
mentation/manual/developer-manual
• Behaviors manual:
http://plone.org/products/dexterity/docu
mentation/manual/behaviors
• Over 30,000 words!
101. Example Code
• example.dexterity
• example.conference
(both in the collective)
• Example code from this talk:
http://svn.plone.org/svn/plone/plone.dext
erity/example.ploneconf09
102. Thanks to everyone who has
contributed to making
Dexterity a reality!
http://www.fickr.com/photos/torley/2862255105/
103. Getting involved
• Google Code project:
http://code.google.com/p/dexterity/
• Google Group:
http://groups.google.com/group/dexterity-
development