SlideShare a Scribd company logo
A Dexterity Intro for Recovering
     Archetypes Addicts


             David Glick
     Plone Symposium East, 2010
What is a content type?
ZODB stores objects
Content type (or portal_type)
categorizes objects




      Page         Something Else
Schema



    (what sort of data can be stored)
Workflow



      (who can do things when)
Custom view templates



        (what it looks like)
Miscellaneous settings
•   Placeful restrictions
•   Comments
•   Searchability
•   Per-type portlet assignments
•   etc.
History Lesson




         http://commons.wikimedia.org/wiki/File:1893_Nina_Pinta_Santa_Maria_replicas.jpg
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
Archetypes
• Schema-based form generation
• Basis of Plone's current default content
  types (ATContentTypes)
• Not going away anytime soon
Dexterity




            Martin Aspeli
Goals




        http://www.fickr.com/photos/paul-w-locke/1662634481/sizes/m/
Make filesystem content type
development sane
Make through-the-web content
type development possible
Make it possible to switch
back and forth between the 2
Philosophy




             http://www.fickr.com/photos/ulrichsson/3519217737/
Reuse over reinvention
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
Natural interaction over
excessive generality


understanding




                time
Real code over generated
code
Zope 3 over Zope 2
Automated testing over
wishful thinking
Example: Photo Gallery
(example.dexgallery in the collective)

• Photo Gallery content type
• Photo content type

• Tagging
• Geolocation
A Dexterity Intro for Recovering Archetypes Addicts
Rapid Development
 Archetypes       Dexterity
• ArchGenXML   • collective.dexteritypaste
• ZopeSkel     $ bin/zopeskel dexterity


               • Though-the-web
                 content type creation
TTW type development
Exporting a type
• GenericSetup export for now;
  better UI coming :)
Base class
  Archetypes                    Dexterity
• BaseObject, usually via   •   plone.dexterity.content.Item or
                                plone.dexterity.content.Container
  ATContentTypes
                            • fewer mixins
• many mixins
                            • custom subclasses
• typically need a custom     typically unneeded
  subclass
Schemas
  Archetypes                     Dexterity
• unique schema format         • Zope 3 schemas
• define a schema, assign it   • Can also be represented in
  to the content class's         a unique XML schema
  'schema' attribute             format
                               • Associated with a content
                                 type via the FTI in
                                 portal_types
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
Schemas
     Archetypes                                Dexterity
From content/photo.py:                     From content/photo.py:
PhotoSchema = atapi.Schema((               class IPhoto(form.Schema):
    # (fields here)                            # (fields here)
))
                                           From profles/default/types/photo.xml:
schemata.finalizeATCTSchema(PhotoSchema,
    moveDiscussion=False)                  <property name="schema">
                                           example.dexgallery.dexterity.content.photo.
class Photo(base.ATCTContent):             IPhoto
    implements(IPhoto)                     </property>
    meta_type = "Photo"
    schema = PhotoSchema
Accessing fields
  Archetypes                     Dexterity
• obj.getField('fieldname')   • obj.fieldname
  .get(obj)                      (values are simply stored
• obj.getFieldname()             as attributes)
  (magically generated         • Use property descriptors if
  accessor on the content        you need custom accessor/
  class)                         mutator logic
                               • __getattr__ makes sure to
                                 get default value from
                                 schema if there's no
                                 attribute stored yet
Field security
• Controlled access (from RestrictedPython)
• Implemented using
  __allow_access_to_unprotected_subobjects__

  Archetypes                     Dexterity
• Read/write permissions       • Read/write permissions
  can be specified per field     can be specified per field
  in the schema                  in the schema
Caption field (rich text)
     Archetypes                               Dexterity
From content/photo.py:                    From content/photo.py:
atapi.TextField('caption',                from plone.app.textfield import RichText
    required = False,
    searchable = True,                    caption = RichText(
    storage =                                 title = _(u'Caption'),
atapi.AnnotationStorage(migrate=True),        required = False,
    validators =                              )
('isTidyHtmlWithCleanup',),
    default_content_type = 'text/html',
    default_output_type = 'text/x-html-
safe',
    widget = atapi.RichWidget(
        label = _(u'Caption'),
        ),
    ),
Photo field (image)
Archetypes
from plone.app.blob.field import ImageField

ImageField('image',
    required = True,
    storage = atapi.AnnotationStorage(migrate=True),
    languageIndependent = True,
    swallowResizeExceptions =
zconf.swallowImageResizeExceptions.enable,
    pil_quality = zconf.pil_config.quality,
    pil_resize_algo = zconf.pil_config.resize_algo,
    max_size = zconf.ATNewsItem.max_image_dimension,
    validators = (('isNonEmptyFile', V_REQUIRED),
        ('checkNewsImageMaxSize', V_REQUIRED)),
    widget = atapi.ImageWidget(
        label = _(u'Photo'),
        show_content_type = False
        ),
    ),
                                                                           Dexterity
                                              from plone.namedfile.field import NamedBlobImage

                                              image = NamedBlobImage(
                                                  title = _(u'Photo'),
                                                  )
Image scaling
• Now supports arbitrary sizes, e.g.
   <img tal:defne="scale photo_obj/@ @ images"
        tal:replace="structure python:scale.scale('image', width=1200,
   height=300, direction='keep').tag()"/>



• (supported for both Archetypes and
  Dexterity in Plone 4)
Tags field (relations)
     Archetypes                              Dexterity
From content/photo.py:                   From content/photo.py:
atapi.ReferenceField(                    from z3c.relationfield.schema import 
    'tags',                                  RelationList, RelationChoice
    storage=atapi.AnnotationStorage(),   tags = RelationList(
    widget=atapi.ReferenceWidget(            title = _(u'Tags'),
        label=_(u"Tags"),                    default = [],
        ),                                   value_type=RelationChoice(
    required=False,                              title = _(u'Tag'),
    relationship='photo_tag',                    source = ObjPathSourceBinder(
    allowed_types=('Document',),                     navigation_tree_query = {'path':
    multiValued=True,                                    {'query':'/'}},
    ),                                               portal_type = 'Document',
                                                     ),
                                                 ),
                                             required = False,
                                             )
Content tree widget
Indexing fields
• similar for both
• for Dexterity you may need to implement
  your own SearchableText indexer, e.g.
from plone.indexer import indexer

@indexer(IPhoto)
def SearchableText(obj):
  return ' '.join([obj.Title(), obj.Description(), obj.caption.output])
Custom views
  Archetypes                    Dexterity

• default: base_view.cpt      • default: view class in
• add a skin layer template     plone.dexterity.browser.view
  or browser view, register   • add a skin layer template or
  in the FTI                    browser view, register in the
                                FTI
Grok-style configuration
• Configuration via directives inline with
  code, instead of via ZCML declarations. e.g.
 from five import grok
 class View(grok.View):
     grok.context(IPhoto)
     grok.require('zope2.View')




• Supported but not required
Custom forms
  Archetypes     Dexterity

• difficult    • full power of z3c.form
                 (write custom forms that
                 reference fields from the
                 type's schema)
               • or, use grok directives on the
                 schema to influence how
                 fields appear in all forms (e.g.,
                 custom widget, etc.)
Adding items
  Archetypes                   Dexterity
• Autogenerated factory      • z3c.form add form
  method                     • Default works in many
• In Plone, portal_factory     cases, but can be replaced
  prevents premature           by setting add_view_expr
  creation and indexing        in the FTI
                             • No content is constructed
                               until the form is submitted
Extending content types
  Archetypes                        Dexterity
• archetypes.schemaextender       • “behaviors”
• “schema extender” adapters      • can provide additional
  can provide additional fields     fields
• “schema modifier” adapters      • can mark the content item
  can make arbitrary changes        with a particular interface
  to a schema                     • can be turned on/off
                                    through the web for each
                                    content type
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
Geolocation behavior
Geolocation behavior
• Adds a geolocation field
• Provides an adapter to store the value of
  that field in an annotation
• Marks the item with IGeolocatableMarker
• Some adapters so that Products.Maps
  knows how to get a geolocation from an
  item with IGeolocatableMarker
Registering a type
  Archetypes                     Dexterity
• registerType() after class   • Just GenericSetup
  definition magically           (profiles/default/types/
  generates Zope 2-style         [Type_Id].xml)
  factory methods
• boilerplate in __init__.py
  finds types and completes
  registration
• type configuration in
  GenericSetup profile
  references the factory
  method
"""Main product initializer                                                        from zope.i18nmessageid import MessageFactory
"""
                                                                                   _ = MessageFactory('example.dexgallery')
from zope.i18nmessageid import MessageFactory
from example.dexgallery.archetypes import config

from Products.Archetypes import atapi
from Products.CMFCore import utils

# Define a message factory for when this product is internationalised.
# This will be imported with the special name "_" in most modules. Strings
# like _(u"message") will then be extracted by i18n tools for translation.

archetypesMessageFactory = MessageFactory('example.dexgallery.archetypes')


def initialize(context):
    """Initializer called when used as a Zope 2 product.

    This is referenced from configure.zcml. Regstrations as a "Zope 2 product"
    is necessary for GenericSetup profiles to work, for example.

    Here, we call the Archetypes machinery to register our content types
    with Zope and the CMF.
    """

    #   Retrieve the content types that have been registered with Archetypes
    #   This happens when the content type is imported and the registerType()
    #   call in the content type's module is invoked. Actually, this happens
    #   during ZCML processing, but we do it here again to be explicit. Of
    #   course, even if we import the module several times, it is only run
    #   once.

    content_types, constructors, ftis = atapi.process_types(
        atapi.listTypes(config.PROJECTNAME),
        config.PROJECTNAME)

    #   Now initialize all these content types. The initialization process takes
    #   care of registering low-level Zope 2 factories, including the relevant
    #   add-permission. These are listed in config.py. We use different
    #   permissions for each content type to allow maximum flexibility of who
    #   can add which content types, where. The roles are set up in rolemap.xml
    #   in the GenericSetup profile.

    for atype, constructor in zip(content_types, constructors):
        utils.ContentInit('%s: %s' % (config.PROJECTNAME, atype.portal_type),
            content_types=(atype, ),
            permission=config.ADD_PERMISSIONS[atype.portal_type],
            extra_constructors=(constructor,),
            ).initialize(context)
Status report / roadmap




            http://www.fickr.com/photos/brianatwebbmoto/2392041992/sizes/m/
Core functionality
Schema serialization
Automatic form
generation
Portlet assignments
Content rules
Relations
• Support for referencing Dexterity content
  from AT content is in progress
Widgets
• Not as rich as Archetypes yet, but better
  than formlib. We have autocomplete,
  browse-for-content, file/image upload.
TTW schema editing
Image & file support
 (via plone.namedfile)
Text transform support
 (via plone.app.textfield)
WebDAV support
Versioning & staging
• In progress
TTW behavior creation
Automatic migration
from Archetypes
content
Multi-lingual content
• Some discussion, but no code yet.
Link integrity checks
Upcoming releases
• First beta release was on Apr. 20
• But, being used in production
• Future releases will support upgrades
Compatibility
• Plone 3
• Plone 4
Performance
Further information
• Installation howto:
  http://plone.org/products/dexterity/documentation/how
  -to/install
• Dexterity manual:
  http://plone.org/products/dexterity/documentation/man
  ual/developer-manual
• Behaviors manual:
  http://plone.org/products/dexterity/documentation/man
  ual/behaviors
Example Code
• example.dexterity
• example.conference
• example.dexgallery
  (in the collective)
Thanks to everyone who has
contributed to making
Dexterity a reality!




                http://www.fickr.com/photos/torley/2862255105/
Getting involved
• Google Code project:
  http://code.google.com/p/dexterity/
• Google Group:
  http://groups.google.com/group/dexterity-
  development

More Related Content

What's hot

The Django Web Application Framework 2
The Django Web Application Framework 2The Django Web Application Framework 2
The Django Web Application Framework 2
fishwarter
 
Building a Dynamic Website Using Django
Building a Dynamic Website Using DjangoBuilding a Dynamic Website Using Django
Building a Dynamic Website Using Django
Nathan Eror
 
Advanced Django
Advanced DjangoAdvanced Django
Advanced Django
Simon Willison
 
Django Architecture Introduction
Django Architecture IntroductionDjango Architecture Introduction
Django Architecture Introduction
Haiqi Chen
 
Introduction To Django (Strange Loop 2011)
Introduction To Django (Strange Loop 2011)Introduction To Django (Strange Loop 2011)
Introduction To Django (Strange Loop 2011)
Jacob Kaplan-Moss
 
jQuery from the very beginning
jQuery from the very beginningjQuery from the very beginning
jQuery from the very beginning
Anis Ahmad
 
PloneNG: What's new in Plone 4.2, 4.3, and beyond
PloneNG: What's new in Plone 4.2, 4.3, and beyondPloneNG: What's new in Plone 4.2, 4.3, and beyond
PloneNG: What's new in Plone 4.2, 4.3, and beyond
David Glick
 
web2py:Web development like a boss
web2py:Web development like a bossweb2py:Web development like a boss
web2py:Web development like a boss
Francisco Ribeiro
 
Django Rest Framework and React and Redux, Oh My!
Django Rest Framework and React and Redux, Oh My!Django Rest Framework and React and Redux, Oh My!
Django Rest Framework and React and Redux, Oh My!
Eric Palakovich Carr
 
[FEConf Korea 2017]Angular 컴포넌트 대화법
[FEConf Korea 2017]Angular 컴포넌트 대화법[FEConf Korea 2017]Angular 컴포넌트 대화법
[FEConf Korea 2017]Angular 컴포넌트 대화법
Jeado Ko
 
Staying Sane with Drupal NEPHP
Staying Sane with Drupal NEPHPStaying Sane with Drupal NEPHP
Staying Sane with Drupal NEPHP
Oscar Merida
 
KAAccessControl
KAAccessControlKAAccessControl
KAAccessControl
WO Community
 
Expression Language in JSP
Expression Language in JSPExpression Language in JSP
Expression Language in JSP
corneliuskoo
 
Bootstrat REST APIs with Laravel 5
Bootstrat REST APIs with Laravel 5Bootstrat REST APIs with Laravel 5
Bootstrat REST APIs with Laravel 5
Elena Kolevska
 
jQuery and_drupal
jQuery and_drupaljQuery and_drupal
jQuery and_drupal
BlackCatWeb
 
Jsp presentation
Jsp presentationJsp presentation
Jsp presentation
Sher Singh Bardhan
 
Django
DjangoDjango
Django
Ivan Widodo
 
Django Framework and Application Structure
Django Framework and Application StructureDjango Framework and Application Structure
Django Framework and Application Structure
SEONGTAEK OH
 
Symfony Guard Authentication: Fun with API Token, Social Login, JWT and more
Symfony Guard Authentication: Fun with API Token, Social Login, JWT and moreSymfony Guard Authentication: Fun with API Token, Social Login, JWT and more
Symfony Guard Authentication: Fun with API Token, Social Login, JWT and more
Ryan Weaver
 
Rich Internet Applications con JavaFX e NetBeans
Rich Internet Applications  con JavaFX e NetBeans Rich Internet Applications  con JavaFX e NetBeans
Rich Internet Applications con JavaFX e NetBeans
Fabrizio Giudici
 

What's hot (20)

The Django Web Application Framework 2
The Django Web Application Framework 2The Django Web Application Framework 2
The Django Web Application Framework 2
 
Building a Dynamic Website Using Django
Building a Dynamic Website Using DjangoBuilding a Dynamic Website Using Django
Building a Dynamic Website Using Django
 
Advanced Django
Advanced DjangoAdvanced Django
Advanced Django
 
Django Architecture Introduction
Django Architecture IntroductionDjango Architecture Introduction
Django Architecture Introduction
 
Introduction To Django (Strange Loop 2011)
Introduction To Django (Strange Loop 2011)Introduction To Django (Strange Loop 2011)
Introduction To Django (Strange Loop 2011)
 
jQuery from the very beginning
jQuery from the very beginningjQuery from the very beginning
jQuery from the very beginning
 
PloneNG: What's new in Plone 4.2, 4.3, and beyond
PloneNG: What's new in Plone 4.2, 4.3, and beyondPloneNG: What's new in Plone 4.2, 4.3, and beyond
PloneNG: What's new in Plone 4.2, 4.3, and beyond
 
web2py:Web development like a boss
web2py:Web development like a bossweb2py:Web development like a boss
web2py:Web development like a boss
 
Django Rest Framework and React and Redux, Oh My!
Django Rest Framework and React and Redux, Oh My!Django Rest Framework and React and Redux, Oh My!
Django Rest Framework and React and Redux, Oh My!
 
[FEConf Korea 2017]Angular 컴포넌트 대화법
[FEConf Korea 2017]Angular 컴포넌트 대화법[FEConf Korea 2017]Angular 컴포넌트 대화법
[FEConf Korea 2017]Angular 컴포넌트 대화법
 
Staying Sane with Drupal NEPHP
Staying Sane with Drupal NEPHPStaying Sane with Drupal NEPHP
Staying Sane with Drupal NEPHP
 
KAAccessControl
KAAccessControlKAAccessControl
KAAccessControl
 
Expression Language in JSP
Expression Language in JSPExpression Language in JSP
Expression Language in JSP
 
Bootstrat REST APIs with Laravel 5
Bootstrat REST APIs with Laravel 5Bootstrat REST APIs with Laravel 5
Bootstrat REST APIs with Laravel 5
 
jQuery and_drupal
jQuery and_drupaljQuery and_drupal
jQuery and_drupal
 
Jsp presentation
Jsp presentationJsp presentation
Jsp presentation
 
Django
DjangoDjango
Django
 
Django Framework and Application Structure
Django Framework and Application StructureDjango Framework and Application Structure
Django Framework and Application Structure
 
Symfony Guard Authentication: Fun with API Token, Social Login, JWT and more
Symfony Guard Authentication: Fun with API Token, Social Login, JWT and moreSymfony Guard Authentication: Fun with API Token, Social Login, JWT and more
Symfony Guard Authentication: Fun with API Token, Social Login, JWT and more
 
Rich Internet Applications con JavaFX e NetBeans
Rich Internet Applications  con JavaFX e NetBeans Rich Internet Applications  con JavaFX e NetBeans
Rich Internet Applications con JavaFX e NetBeans
 

Similar to A Dexterity Intro for Recovering Archetypes Addicts

Group111
Group111Group111
201005 accelerometer and core Location
201005 accelerometer and core Location201005 accelerometer and core Location
201005 accelerometer and core Location
Javier Gonzalez-Sanchez
 
Real World MVC
Real World MVCReal World MVC
Real World MVC
James Johnson
 
Powerful Generic Patterns With Django
Powerful Generic Patterns With DjangoPowerful Generic Patterns With Django
Powerful Generic Patterns With Django
Eric Satterwhite
 
CIRCUIT 2015 - Content API's For AEM Sites
CIRCUIT 2015 - Content API's For AEM SitesCIRCUIT 2015 - Content API's For AEM Sites
CIRCUIT 2015 - Content API's For AEM Sites
ICF CIRCUIT
 
The CoFX Data Model
The CoFX Data ModelThe CoFX Data Model
The CoFX Data Model
Rainer Stropek
 
Eclipse Day India 2011 - Extending JDT
Eclipse Day India 2011 - Extending JDTEclipse Day India 2011 - Extending JDT
Eclipse Day India 2011 - Extending JDT
deepakazad
 
Object-oriented programming
Object-oriented programmingObject-oriented programming
Object-oriented programming
Neelesh Shukla
 
Advanced guide to develop ajax applications using dojo
Advanced guide to develop ajax applications using dojoAdvanced guide to develop ajax applications using dojo
Advanced guide to develop ajax applications using dojo
Fu Cheng
 
Python Deserialization Attacks
Python Deserialization AttacksPython Deserialization Attacks
Python Deserialization Attacks
NSConclave
 
From YUI3 to K2
From YUI3 to K2From YUI3 to K2
From YUI3 to K2
kaven yan
 
Eclipse e4
Eclipse e4Eclipse e4
Eclipse e4
Chris Aniszczyk
 
Object Oriented PHP Overview
Object Oriented PHP OverviewObject Oriented PHP Overview
Object Oriented PHP Overview
Larry Ball
 
Sling Models Using Sightly and JSP by Deepak Khetawat
Sling Models Using Sightly and JSP by Deepak KhetawatSling Models Using Sightly and JSP by Deepak Khetawat
Sling Models Using Sightly and JSP by Deepak Khetawat
AEM HUB
 
Jpa
JpaJpa
The Naked Bundle - Symfony Live London 2014
The Naked Bundle - Symfony Live London 2014The Naked Bundle - Symfony Live London 2014
The Naked Bundle - Symfony Live London 2014
Matthias Noback
 
Page Fragments как развитие идеи Page Object паттерна
Page Fragments как развитие идеи Page Object паттернаPage Fragments как развитие идеи Page Object паттерна
Page Fragments как развитие идеи Page Object паттерна
Start IT training center
 
Deepak khetawat sling_models_sightly_jsp
Deepak khetawat sling_models_sightly_jspDeepak khetawat sling_models_sightly_jsp
Deepak khetawat sling_models_sightly_jsp
DEEPAK KHETAWAT
 
JavaScript Coding with Class
JavaScript Coding with ClassJavaScript Coding with Class
JavaScript Coding with Class
davidwalsh83
 
Owner - Java properties reinvented.
Owner - Java properties reinvented.Owner - Java properties reinvented.
Owner - Java properties reinvented.
Luigi Viggiano
 

Similar to A Dexterity Intro for Recovering Archetypes Addicts (20)

Group111
Group111Group111
Group111
 
201005 accelerometer and core Location
201005 accelerometer and core Location201005 accelerometer and core Location
201005 accelerometer and core Location
 
Real World MVC
Real World MVCReal World MVC
Real World MVC
 
Powerful Generic Patterns With Django
Powerful Generic Patterns With DjangoPowerful Generic Patterns With Django
Powerful Generic Patterns With Django
 
CIRCUIT 2015 - Content API's For AEM Sites
CIRCUIT 2015 - Content API's For AEM SitesCIRCUIT 2015 - Content API's For AEM Sites
CIRCUIT 2015 - Content API's For AEM Sites
 
The CoFX Data Model
The CoFX Data ModelThe CoFX Data Model
The CoFX Data Model
 
Eclipse Day India 2011 - Extending JDT
Eclipse Day India 2011 - Extending JDTEclipse Day India 2011 - Extending JDT
Eclipse Day India 2011 - Extending JDT
 
Object-oriented programming
Object-oriented programmingObject-oriented programming
Object-oriented programming
 
Advanced guide to develop ajax applications using dojo
Advanced guide to develop ajax applications using dojoAdvanced guide to develop ajax applications using dojo
Advanced guide to develop ajax applications using dojo
 
Python Deserialization Attacks
Python Deserialization AttacksPython Deserialization Attacks
Python Deserialization Attacks
 
From YUI3 to K2
From YUI3 to K2From YUI3 to K2
From YUI3 to K2
 
Eclipse e4
Eclipse e4Eclipse e4
Eclipse e4
 
Object Oriented PHP Overview
Object Oriented PHP OverviewObject Oriented PHP Overview
Object Oriented PHP Overview
 
Sling Models Using Sightly and JSP by Deepak Khetawat
Sling Models Using Sightly and JSP by Deepak KhetawatSling Models Using Sightly and JSP by Deepak Khetawat
Sling Models Using Sightly and JSP by Deepak Khetawat
 
Jpa
JpaJpa
Jpa
 
The Naked Bundle - Symfony Live London 2014
The Naked Bundle - Symfony Live London 2014The Naked Bundle - Symfony Live London 2014
The Naked Bundle - Symfony Live London 2014
 
Page Fragments как развитие идеи Page Object паттерна
Page Fragments как развитие идеи Page Object паттернаPage Fragments как развитие идеи Page Object паттерна
Page Fragments как развитие идеи Page Object паттерна
 
Deepak khetawat sling_models_sightly_jsp
Deepak khetawat sling_models_sightly_jspDeepak khetawat sling_models_sightly_jsp
Deepak khetawat sling_models_sightly_jsp
 
JavaScript Coding with Class
JavaScript Coding with ClassJavaScript Coding with Class
JavaScript Coding with Class
 
Owner - Java properties reinvented.
Owner - Java properties reinvented.Owner - Java properties reinvented.
Owner - Java properties reinvented.
 

Recently uploaded

Uncharted Together- Navigating AI's New Frontiers in Libraries
Uncharted Together- Navigating AI's New Frontiers in LibrariesUncharted Together- Navigating AI's New Frontiers in Libraries
Uncharted Together- Navigating AI's New Frontiers in Libraries
Brian Pichman
 
leewayhertz.com-AI agents for healthcare Applications benefits and implementa...
leewayhertz.com-AI agents for healthcare Applications benefits and implementa...leewayhertz.com-AI agents for healthcare Applications benefits and implementa...
leewayhertz.com-AI agents for healthcare Applications benefits and implementa...
alexjohnson7307
 
Google I/O Extended Harare Merged Slides
Google I/O Extended Harare Merged SlidesGoogle I/O Extended Harare Merged Slides
Google I/O Extended Harare Merged Slides
Google Developer Group - Harare
 
Computer HARDWARE presenattion by CWD students class 10
Computer HARDWARE presenattion by CWD students class 10Computer HARDWARE presenattion by CWD students class 10
Computer HARDWARE presenattion by CWD students class 10
ankush9927
 
High Profile Girls Call ServiCe Hyderabad 0000000000 Tanisha Best High Class ...
High Profile Girls Call ServiCe Hyderabad 0000000000 Tanisha Best High Class ...High Profile Girls Call ServiCe Hyderabad 0000000000 Tanisha Best High Class ...
High Profile Girls Call ServiCe Hyderabad 0000000000 Tanisha Best High Class ...
aslasdfmkhan4750
 
Introduction-to-the-IAM-Platform-Implementation-Plan.pptx
Introduction-to-the-IAM-Platform-Implementation-Plan.pptxIntroduction-to-the-IAM-Platform-Implementation-Plan.pptx
Introduction-to-the-IAM-Platform-Implementation-Plan.pptx
313mohammedarshad
 
High Profile Girls call Service Pune 000XX00000 Provide Best And Top Girl Ser...
High Profile Girls call Service Pune 000XX00000 Provide Best And Top Girl Ser...High Profile Girls call Service Pune 000XX00000 Provide Best And Top Girl Ser...
High Profile Girls call Service Pune 000XX00000 Provide Best And Top Girl Ser...
bhumivarma35300
 
The importance of Quality Assurance for ICT Standardization
The importance of Quality Assurance for ICT StandardizationThe importance of Quality Assurance for ICT Standardization
The importance of Quality Assurance for ICT Standardization
Axel Rennoch
 
BT & Neo4j: Knowledge Graphs for Critical Enterprise Systems.pptx.pdf
BT & Neo4j: Knowledge Graphs for Critical Enterprise Systems.pptx.pdfBT & Neo4j: Knowledge Graphs for Critical Enterprise Systems.pptx.pdf
BT & Neo4j: Knowledge Graphs for Critical Enterprise Systems.pptx.pdf
Neo4j
 
Patch Tuesday de julio
Patch Tuesday de julioPatch Tuesday de julio
Patch Tuesday de julio
Ivanti
 
Data Integration Basics: Merging & Joining Data
Data Integration Basics: Merging & Joining DataData Integration Basics: Merging & Joining Data
Data Integration Basics: Merging & Joining Data
Safe Software
 
Mastering OnlyFans Clone App Development: Key Strategies for Success
Mastering OnlyFans Clone App Development: Key Strategies for SuccessMastering OnlyFans Clone App Development: Key Strategies for Success
Mastering OnlyFans Clone App Development: Key Strategies for Success
David Wilson
 
IPLOOK Remote-Sensing Satellite Solution
IPLOOK Remote-Sensing Satellite SolutionIPLOOK Remote-Sensing Satellite Solution
IPLOOK Remote-Sensing Satellite Solution
IPLOOK Networks
 
Three New Criminal Laws in India 1 July 2024
Three New Criminal Laws in India 1 July 2024Three New Criminal Laws in India 1 July 2024
Three New Criminal Laws in India 1 July 2024
aakash malhotra
 
How to Build a Profitable IoT Product.pptx
How to Build a Profitable IoT Product.pptxHow to Build a Profitable IoT Product.pptx
How to Build a Profitable IoT Product.pptx
Adam Dunkels
 
Russian Girls Call Navi Mumbai 🎈🔥9920725232 🔥💋🎈 Provide Best And Top Girl Ser...
Russian Girls Call Navi Mumbai 🎈🔥9920725232 🔥💋🎈 Provide Best And Top Girl Ser...Russian Girls Call Navi Mumbai 🎈🔥9920725232 🔥💋🎈 Provide Best And Top Girl Ser...
Russian Girls Call Navi Mumbai 🎈🔥9920725232 🔥💋🎈 Provide Best And Top Girl Ser...
bellared2
 
Integrating Kafka with MuleSoft 4 and usecase
Integrating Kafka with MuleSoft 4 and usecaseIntegrating Kafka with MuleSoft 4 and usecase
Integrating Kafka with MuleSoft 4 and usecase
shyamraj55
 
Vulnerability Management: A Comprehensive Overview
Vulnerability Management: A Comprehensive OverviewVulnerability Management: A Comprehensive Overview
Vulnerability Management: A Comprehensive Overview
Steven Carlson
 
BLOCKCHAIN TECHNOLOGY - Advantages and Disadvantages
BLOCKCHAIN TECHNOLOGY - Advantages and DisadvantagesBLOCKCHAIN TECHNOLOGY - Advantages and Disadvantages
BLOCKCHAIN TECHNOLOGY - Advantages and Disadvantages
SAI KAILASH R
 
The Role of IoT in Australian Mobile App Development - PDF Guide
The Role of IoT in Australian Mobile App Development - PDF GuideThe Role of IoT in Australian Mobile App Development - PDF Guide
The Role of IoT in Australian Mobile App Development - PDF Guide
Shiv Technolabs
 

Recently uploaded (20)

Uncharted Together- Navigating AI's New Frontiers in Libraries
Uncharted Together- Navigating AI's New Frontiers in LibrariesUncharted Together- Navigating AI's New Frontiers in Libraries
Uncharted Together- Navigating AI's New Frontiers in Libraries
 
leewayhertz.com-AI agents for healthcare Applications benefits and implementa...
leewayhertz.com-AI agents for healthcare Applications benefits and implementa...leewayhertz.com-AI agents for healthcare Applications benefits and implementa...
leewayhertz.com-AI agents for healthcare Applications benefits and implementa...
 
Google I/O Extended Harare Merged Slides
Google I/O Extended Harare Merged SlidesGoogle I/O Extended Harare Merged Slides
Google I/O Extended Harare Merged Slides
 
Computer HARDWARE presenattion by CWD students class 10
Computer HARDWARE presenattion by CWD students class 10Computer HARDWARE presenattion by CWD students class 10
Computer HARDWARE presenattion by CWD students class 10
 
High Profile Girls Call ServiCe Hyderabad 0000000000 Tanisha Best High Class ...
High Profile Girls Call ServiCe Hyderabad 0000000000 Tanisha Best High Class ...High Profile Girls Call ServiCe Hyderabad 0000000000 Tanisha Best High Class ...
High Profile Girls Call ServiCe Hyderabad 0000000000 Tanisha Best High Class ...
 
Introduction-to-the-IAM-Platform-Implementation-Plan.pptx
Introduction-to-the-IAM-Platform-Implementation-Plan.pptxIntroduction-to-the-IAM-Platform-Implementation-Plan.pptx
Introduction-to-the-IAM-Platform-Implementation-Plan.pptx
 
High Profile Girls call Service Pune 000XX00000 Provide Best And Top Girl Ser...
High Profile Girls call Service Pune 000XX00000 Provide Best And Top Girl Ser...High Profile Girls call Service Pune 000XX00000 Provide Best And Top Girl Ser...
High Profile Girls call Service Pune 000XX00000 Provide Best And Top Girl Ser...
 
The importance of Quality Assurance for ICT Standardization
The importance of Quality Assurance for ICT StandardizationThe importance of Quality Assurance for ICT Standardization
The importance of Quality Assurance for ICT Standardization
 
BT & Neo4j: Knowledge Graphs for Critical Enterprise Systems.pptx.pdf
BT & Neo4j: Knowledge Graphs for Critical Enterprise Systems.pptx.pdfBT & Neo4j: Knowledge Graphs for Critical Enterprise Systems.pptx.pdf
BT & Neo4j: Knowledge Graphs for Critical Enterprise Systems.pptx.pdf
 
Patch Tuesday de julio
Patch Tuesday de julioPatch Tuesday de julio
Patch Tuesday de julio
 
Data Integration Basics: Merging & Joining Data
Data Integration Basics: Merging & Joining DataData Integration Basics: Merging & Joining Data
Data Integration Basics: Merging & Joining Data
 
Mastering OnlyFans Clone App Development: Key Strategies for Success
Mastering OnlyFans Clone App Development: Key Strategies for SuccessMastering OnlyFans Clone App Development: Key Strategies for Success
Mastering OnlyFans Clone App Development: Key Strategies for Success
 
IPLOOK Remote-Sensing Satellite Solution
IPLOOK Remote-Sensing Satellite SolutionIPLOOK Remote-Sensing Satellite Solution
IPLOOK Remote-Sensing Satellite Solution
 
Three New Criminal Laws in India 1 July 2024
Three New Criminal Laws in India 1 July 2024Three New Criminal Laws in India 1 July 2024
Three New Criminal Laws in India 1 July 2024
 
How to Build a Profitable IoT Product.pptx
How to Build a Profitable IoT Product.pptxHow to Build a Profitable IoT Product.pptx
How to Build a Profitable IoT Product.pptx
 
Russian Girls Call Navi Mumbai 🎈🔥9920725232 🔥💋🎈 Provide Best And Top Girl Ser...
Russian Girls Call Navi Mumbai 🎈🔥9920725232 🔥💋🎈 Provide Best And Top Girl Ser...Russian Girls Call Navi Mumbai 🎈🔥9920725232 🔥💋🎈 Provide Best And Top Girl Ser...
Russian Girls Call Navi Mumbai 🎈🔥9920725232 🔥💋🎈 Provide Best And Top Girl Ser...
 
Integrating Kafka with MuleSoft 4 and usecase
Integrating Kafka with MuleSoft 4 and usecaseIntegrating Kafka with MuleSoft 4 and usecase
Integrating Kafka with MuleSoft 4 and usecase
 
Vulnerability Management: A Comprehensive Overview
Vulnerability Management: A Comprehensive OverviewVulnerability Management: A Comprehensive Overview
Vulnerability Management: A Comprehensive Overview
 
BLOCKCHAIN TECHNOLOGY - Advantages and Disadvantages
BLOCKCHAIN TECHNOLOGY - Advantages and DisadvantagesBLOCKCHAIN TECHNOLOGY - Advantages and Disadvantages
BLOCKCHAIN TECHNOLOGY - Advantages and Disadvantages
 
The Role of IoT in Australian Mobile App Development - PDF Guide
The Role of IoT in Australian Mobile App Development - PDF GuideThe Role of IoT in Australian Mobile App Development - PDF Guide
The Role of IoT in Australian Mobile App Development - PDF Guide
 

A Dexterity Intro for Recovering Archetypes Addicts

  • 1. A Dexterity Intro for Recovering Archetypes Addicts David Glick Plone Symposium East, 2010
  • 2. What is a content type?
  • 4. Content type (or portal_type) categorizes objects Page Something Else
  • 5. Schema (what sort of data can be stored)
  • 6. Workflow (who can do things when)
  • 7. Custom view templates (what it looks like)
  • 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 possible
  • 16. Make it possible to switch back and forth between the 2
  • 17. Philosophy http://www.fickr.com/photos/ulrichsson/3519217737/
  • 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 understanding time
  • 21. Real code over generated code
  • 22. Zope 3 over Zope 2
  • 24. Example: Photo Gallery (example.dexgallery in the collective) • Photo Gallery content type • Photo content type • Tagging • Geolocation
  • 26. Rapid Development Archetypes Dexterity • ArchGenXML • collective.dexteritypaste • ZopeSkel $ bin/zopeskel dexterity • Though-the-web content type creation
  • 28. Exporting a type • GenericSetup export for now; better UI coming :)
  • 29. Base class Archetypes Dexterity • BaseObject, usually via • plone.dexterity.content.Item or plone.dexterity.content.Container ATContentTypes • fewer mixins • many mixins • custom subclasses • typically need a custom typically unneeded subclass
  • 30. Schemas Archetypes Dexterity • unique schema format • Zope 3 schemas • define a schema, assign it • Can also be represented in to the content class's a unique XML schema 'schema' attribute format • Associated with a content type via the FTI in portal_types
  • 31. 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
  • 32. Schemas Archetypes Dexterity From content/photo.py: From content/photo.py: PhotoSchema = atapi.Schema(( class IPhoto(form.Schema): # (fields here) # (fields here) )) From profles/default/types/photo.xml: schemata.finalizeATCTSchema(PhotoSchema, moveDiscussion=False) <property name="schema"> example.dexgallery.dexterity.content.photo. class Photo(base.ATCTContent): IPhoto implements(IPhoto) </property> meta_type = "Photo" schema = PhotoSchema
  • 33. Accessing fields Archetypes Dexterity • obj.getField('fieldname') • obj.fieldname .get(obj) (values are simply stored • obj.getFieldname() as attributes) (magically generated • Use property descriptors if accessor on the content you need custom accessor/ class) mutator logic • __getattr__ makes sure to get default value from schema if there's no attribute stored yet
  • 34. Field security • Controlled access (from RestrictedPython) • Implemented using __allow_access_to_unprotected_subobjects__ Archetypes Dexterity • Read/write permissions • Read/write permissions can be specified per field can be specified per field in the schema in the schema
  • 35. Caption field (rich text) Archetypes Dexterity From content/photo.py: From content/photo.py: atapi.TextField('caption', from plone.app.textfield import RichText required = False, searchable = True, caption = RichText( storage = title = _(u'Caption'), atapi.AnnotationStorage(migrate=True), required = False, validators = ) ('isTidyHtmlWithCleanup',), default_content_type = 'text/html', default_output_type = 'text/x-html- safe', widget = atapi.RichWidget( label = _(u'Caption'), ), ),
  • 36. Photo field (image) Archetypes from plone.app.blob.field import ImageField ImageField('image', required = True, storage = atapi.AnnotationStorage(migrate=True), languageIndependent = True, swallowResizeExceptions = zconf.swallowImageResizeExceptions.enable, pil_quality = zconf.pil_config.quality, pil_resize_algo = zconf.pil_config.resize_algo, max_size = zconf.ATNewsItem.max_image_dimension, validators = (('isNonEmptyFile', V_REQUIRED), ('checkNewsImageMaxSize', V_REQUIRED)), widget = atapi.ImageWidget( label = _(u'Photo'), show_content_type = False ), ), Dexterity from plone.namedfile.field import NamedBlobImage image = NamedBlobImage( title = _(u'Photo'), )
  • 37. Image scaling • Now supports arbitrary sizes, e.g. <img tal:defne="scale photo_obj/@ @ images" tal:replace="structure python:scale.scale('image', width=1200, height=300, direction='keep').tag()"/> • (supported for both Archetypes and Dexterity in Plone 4)
  • 38. Tags field (relations) Archetypes Dexterity From content/photo.py: From content/photo.py: atapi.ReferenceField( from z3c.relationfield.schema import 'tags', RelationList, RelationChoice storage=atapi.AnnotationStorage(), tags = RelationList( widget=atapi.ReferenceWidget( title = _(u'Tags'), label=_(u"Tags"), default = [], ), value_type=RelationChoice( required=False, title = _(u'Tag'), relationship='photo_tag', source = ObjPathSourceBinder( allowed_types=('Document',), navigation_tree_query = {'path': multiValued=True, {'query':'/'}}, ), portal_type = 'Document', ), ), required = False, )
  • 40. Indexing fields • similar for both • for Dexterity you may need to implement your own SearchableText indexer, e.g. from plone.indexer import indexer @indexer(IPhoto) def SearchableText(obj): return ' '.join([obj.Title(), obj.Description(), obj.caption.output])
  • 41. Custom views Archetypes Dexterity • default: base_view.cpt • default: view class in • add a skin layer template plone.dexterity.browser.view or browser view, register • add a skin layer template or in the FTI browser view, register in the FTI
  • 42. Grok-style configuration • Configuration via directives inline with code, instead of via ZCML declarations. e.g. from five import grok class View(grok.View): grok.context(IPhoto) grok.require('zope2.View') • Supported but not required
  • 43. Custom forms Archetypes Dexterity • difficult • full power of z3c.form (write custom forms that reference fields from the type's schema) • or, use grok directives on the schema to influence how fields appear in all forms (e.g., custom widget, etc.)
  • 44. Adding items Archetypes Dexterity • Autogenerated factory • z3c.form add form method • Default works in many • In Plone, portal_factory cases, but can be replaced prevents premature by setting add_view_expr creation and indexing in the FTI • No content is constructed until the form is submitted
  • 45. Extending content types Archetypes Dexterity • archetypes.schemaextender • “behaviors” • “schema extender” adapters • can provide additional can provide additional fields fields • “schema modifier” adapters • can mark the content item can make arbitrary changes with a particular interface to a schema • can be turned on/off through the web for each content type
  • 46. 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
  • 48. Geolocation behavior • Adds a geolocation field • Provides an adapter to store the value of that field in an annotation • Marks the item with IGeolocatableMarker • Some adapters so that Products.Maps knows how to get a geolocation from an item with IGeolocatableMarker
  • 49. Registering a type Archetypes Dexterity • registerType() after class • Just GenericSetup definition magically (profiles/default/types/ generates Zope 2-style [Type_Id].xml) factory methods • boilerplate in __init__.py finds types and completes registration • type configuration in GenericSetup profile references the factory method
  • 50. """Main product initializer from zope.i18nmessageid import MessageFactory """ _ = MessageFactory('example.dexgallery') from zope.i18nmessageid import MessageFactory from example.dexgallery.archetypes import config from Products.Archetypes import atapi from Products.CMFCore import utils # Define a message factory for when this product is internationalised. # This will be imported with the special name "_" in most modules. Strings # like _(u"message") will then be extracted by i18n tools for translation. archetypesMessageFactory = MessageFactory('example.dexgallery.archetypes') def initialize(context): """Initializer called when used as a Zope 2 product. This is referenced from configure.zcml. Regstrations as a "Zope 2 product" is necessary for GenericSetup profiles to work, for example. Here, we call the Archetypes machinery to register our content types with Zope and the CMF. """ # Retrieve the content types that have been registered with Archetypes # This happens when the content type is imported and the registerType() # call in the content type's module is invoked. Actually, this happens # during ZCML processing, but we do it here again to be explicit. Of # course, even if we import the module several times, it is only run # once. content_types, constructors, ftis = atapi.process_types( atapi.listTypes(config.PROJECTNAME), config.PROJECTNAME) # Now initialize all these content types. The initialization process takes # care of registering low-level Zope 2 factories, including the relevant # add-permission. These are listed in config.py. We use different # permissions for each content type to allow maximum flexibility of who # can add which content types, where. The roles are set up in rolemap.xml # in the GenericSetup profile. for atype, constructor in zip(content_types, constructors): utils.ContentInit('%s: %s' % (config.PROJECTNAME, atype.portal_type), content_types=(atype, ), permission=config.ADD_PERMISSIONS[atype.portal_type], extra_constructors=(constructor,), ).initialize(context)
  • 51. Status report / roadmap http://www.fickr.com/photos/brianatwebbmoto/2392041992/sizes/m/
  • 57. Relations • Support for referencing Dexterity content from AT content is in progress
  • 58. Widgets • Not as rich as Archetypes yet, but better than formlib. We have autocomplete, browse-for-content, file/image upload.
  • 60. Image & file support (via plone.namedfile)
  • 61. Text transform support (via plone.app.textfield)
  • 66. Multi-lingual content • Some discussion, but no code yet.
  • 68. Upcoming releases • First beta release was on Apr. 20 • But, being used in production • Future releases will support upgrades
  • 71. Further information • Installation howto: http://plone.org/products/dexterity/documentation/how -to/install • Dexterity manual: http://plone.org/products/dexterity/documentation/man ual/developer-manual • Behaviors manual: http://plone.org/products/dexterity/documentation/man ual/behaviors
  • 72. Example Code • example.dexterity • example.conference • example.dexgallery (in the collective)
  • 73. Thanks to everyone who has contributed to making Dexterity a reality! http://www.fickr.com/photos/torley/2862255105/
  • 74. Getting involved • Google Code project: http://code.google.com/p/dexterity/ • Google Group: http://groups.google.com/group/dexterity- development