Building Content Types with Dexterity

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    1 Favorite

    Building Content Types with Dexterity - Presentation Transcript

    1. Building Content Types with Dexterity David Glick Plone Conference 2009
    2. Groundwire uses the power of technology to connect people, organizations, and communities working to build a sustainable society.
    3. What is a content type?
    4. A way of categorizing the items in your site Page Something Else
    5. Schema
    6. Workflow
    7. Custom view templates
    8. Miscellaneous settings • Placeful restrictions • Comments • Searchability • Per-type portlet assignments • etc.
    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
    12. Dexterity Martin Aspeli
    13. Goals http://www.fickr.com/photos/paul-w-locke/1662634481/sizes/m/
    14. Make filesystem content type development sane
    15. Make through-the-web content type development sane
    16. Make it possible to switch back and forth between the 2
    17. Philosophy http://www.fickr.com/photos/ulrichsson/3519217737/
    18. Reuse over reinvention
    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
    20. Natural interaction over excessive generality diffculty time
    21. Real code over generated code
    22. Zope 3 over Zope 2
    23. Automated testing over wishful thinking
    24. Let's build a content type!
    25. Installing Dexterity [buildout] extends = http://dist.plone.org/release/3.3.1/versions.cfg http://good-py.appspot.com/release/dexterity/1.0a2 … [instance] … eggs = … plone.app.dexterity
    26. Installing Dexterity
    27. Dexterity Types Control Panel
    28. Adding a Type
    29. Adding a Type
    30. Adding a 'Plonista' instance
    31. Adding a 'Plonista' instance
    32. The default 'Plonista' view
    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
    36. Adding a Field
    37. Adding a Field This will replace the title feld that used to come from the Dublin Core behavior.
    38. Adding a Field
    39. Editing a field We are changing the title of this feld to 'Name'.
    40. Edit a revised 'Plonista'
    41. 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.
    42. 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.
    43. 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)
    44. 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
    45. Exporting a type • GenericSetup export for now; better UI coming :)
    46. Minimal Dexterity package structure • example.ploneconf09 » /example • /ploneconf09 • /__init__.py • /configure.zcml • /profiles • /default • /metadata.xml • /types.xml • /types • plonista.xml » /setup.py
    47. 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) """, )
    48. __init__.py # Nothing to see here; move along. :)
    49. configure.zcml <configure xmlns="http://namespaces.zope.org/zope" xmlns:grok="http://namespaces.zope.org/grok" xmlns:genericsetup="http://namespaces.zope.org/genericsetup" i18n_domain="example.ploneconf09"> Loads ZCML for all dependency <includeDependencies package="."/> packages listed in setup.py <genericsetup:registerProfile name="default" title="Plone conference Dexterity example" directory="profiles/default" description="Installs the Dexterity example for the Plone conference." provides="Products.GenericSetup.interfaces.EXTENSION" /> </configure>
    50. types.xml <?xml version="1.0"?> <object name="portal_types" meta_type="Plone Types Tool"> <object name="plonista" meta_type="Dexterity FTI"/> </object> metadata.xml <metadata> <version>1</version> <dependencies> <dependency>profile-plone.app.dexterity:default</dependency> </dependencies> </metadata>
    51. plonista.xml <?xml version="1.0"?> <object name="plonista" meta_type="Dexterity FTI" xmlns:i18n="http://xml.zope.org/namespaces/i18n"> <property name="title">Plonista</property> <property name="description">A member of the Plone community.</property> <property name="content_icon">document_icon.png</property> <property name="icon_expr">string:${portal_url}/document_icon.png</property> <property name="factory">plonista</property> <property name="link_target"></property> <property name="immediate_view">view</property> <property name="global_allow">True</property> <property name="filter_content_types">True</property> <property name="allowed_content_types"/> <property name="allow_discussion">False</property> <property name="default_view">view</property> <property name="view_methods"> <element value="view"/> </property> <property name="default_view_fallback">False</property>
    52. 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">&lt;model xmlns="http://namespaces.plone.org/supermodel/schema"&gt; &lt;schema&gt; &lt;field name="title" type="zope.schema.TextLine"&gt; &lt;description /&gt; &lt;title&gt;Name&lt;/title&gt; &lt;/field&gt; &lt;field name="portrait" type="plone.namedfile.field.NamedBlobImage"&gt; &lt;title&gt;Portrait&lt;/title&gt; &lt;/field&gt; &lt;field name="bio" type="plone.app.textfield.RichText"&gt; &lt;title&gt;Bio&lt;/title&gt; &lt;/field&gt; &lt;/schema&gt; &lt;/model&gt;</property> <property name="model_file"></property> Can put model in a separate fle. (These are the Dexterity-specifc bits.)
    53. plonista.xml (continued) <alias from="(Default)" to="(selected layout)"/> <alias from="edit" to="@@edit"/> <alias from="sharing" to="@@sharing"/> <alias from="view" to="@@view"/> <action title="View" action_id="view" category="object" condition_expr="" icon_expr="" link_target="" url_expr="string:${object_url}" visible="True"> <permission value="View"/> </action> <action title="Edit" action_id="edit" category="object" condition_expr="" icon_expr="" link_target="" url_expr="string:${object_url}/edit" visible="True"> <permission value="Modify portal content"/> </action> </object>
    54. 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
    55. 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, )
    56. 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>
    57. Specifying a fieldset class IPlonista(form.Schema): … bio = RichText( title=u'Bio', required = False, ) form.fieldset( 'bio', label=u'Bio', fields=['bio'], )
    58. More form directives • widget – specify alternate widget • omitted – omits fields • mode – input, display, or hidden • order_before, order_after – adjust position
    59. plone.directives.dexterity • read_permission • write_permission
    60. Custom view template • In plonista.py: from five import grok class View(grok.View): grok.context(IPlonista) grok.require('zope2.View')
    61. • In plonista_templates/view.pt <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" xmlns:tal="http://xml.zope.org/namespaces/tal" xmlns:metal="http://xml.zope.org/namespaces/metal" xmlns:i18n="http://xml.zope.org/namespaces/i18n" lang="en" metal:use-macro="context/main_template/macros/master" i18n:domain="example.conference"> <body> <metal:main fill-slot="main"> <tal:main-macro metal:define-macro="main"> <div tal:replace="structure provider:plone.abovecontenttitle" /> <h1 class="documentFirstHeading" tal:content="context/title" /> <div tal:replace="structure provider:plone.belowcontenttitle" /> <div tal:replace="structure provider:plone.abovecontentbody" /> <div tal:define="portrait nocall:context/portrait" tal:condition="nocall:portrait"><img tal:attributes="src string:${context/absolute_url}/@@download/portrait/${portrait/filename}; height portrait/_height | nothing; width portrait/_width | nothing;" /> </div> <div tal:content="structure context/bio/output" /> <div tal:replace="structure provider:plone.belowcontentbody" /> </tal:main-macro> </metal:main> </body> </html>
    62. Add the package to buildout [buildout] develop = src/example.ploneconf09 [instance] … eggs = … example.ploneconf09
    63. Install the new package
    64. Existing content automatically provides the new schema
    65. The custom view
    66. The pieces http://www.fickr.com/photos/intvgene/370973576/
    67. 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="." />
    68. plone.dexterity • Base content classes. • FTI (Factory Type Information) provides for dynamic lookup of model and schema. • Default edit form and view.
    69. 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.)
    70. 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.
    71. 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
    72. 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.
    73. plone.directives.dexterity • Grok directives for custom content classes and forms.
    74. plone.folder • Orderable Btree-based folder implementation. • Will also be the basis for AT-based folders in Plone 4.
    75. 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.
    76. plone.rfc822 • Supports the marshalling of Dexterity content into RFC 822 format. • Used to support access via WebDAV.
    77. plone.app.dexterity • Pulls in everything you need. • Standard behaviors. » Dublin Core » Related Items • Dexterity types control panel.
    78. Status report / roadmap http://www.fickr.com/photos/brianatwebbmoto/2392041992/sizes/m/
    79. Core functionality
    80. Schema serialization
    81. Automatic form generation
    82. Portlet assignments
    83. Content rules
    84. Relations • Not working between Archetypes and Dexterity content in the same site
    85. Widgets • Not as rich as Archetypes yet, but better than formlib. We have autocomplete, browse-for-content, file/image upload.
    86. TTW schema editing • Works fine, but needs more real-life use.
    87. Image & file support (via plone.namedfile & plone.formwidget.namedfile) • No support for image scaling yet.
    88. Text transform support (via plone.app.textfield)
    89. Select field support • No way to define vocabularies through the web yet.
    90. WebDAV support
    91. Versioning & staging • In progress
    92. TTW behavior creation
    93. Automatic migration from Archetypes content
    94. Multi-lingual content • Some discussion, but no code yet.
    95. Link integrity checks
    96. Upcoming releases • Second alpha release was on Oct. 12 • First beta release coming soon
    97. Compatibility • Plone 3 • Plone 4 compatibility coming soon
    98. Performance
    99. 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!
    100. 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
    101. Thanks to everyone who has contributed to making Dexterity a reality! http://www.fickr.com/photos/torley/2862255105/
    102. Getting involved • Google Code project: http://code.google.com/p/dexterity/ • Google Group: http://groups.google.com/group/dexterity- development

    + David GlickDavid Glick, 3 weeks ago

    custom

    306 views, 1 favs, 0 embeds more stats

    David Glick's Plone Conference 2009 tutorial on bui more

    More info about this document

    CC Attribution-NonCommercial-ShareAlike LicenseCC Attribution-NonCommercial-ShareAlike LicenseCC Attribution-NonCommercial-ShareAlike License

    Go to text version

    • Total Views 306
      • 306 on SlideShare
      • 0 from embeds
    • Comments 0
    • Favorites 1
    • Downloads 11
    Most viewed embeds

    more

    All embeds

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories