How to subclass an ATContentType in 7 Minutes

by Jens W. Klein last modified Dec 30, 2008 03:02 PM
Learn how to subclass an ATContentTypes type (types used in Plone 2.1, like Page, Image, etc.) using UML and ArchGenXML. In this how-to we're creating an ATDocument derivate where content itself is a page template.

Note: a minimal version with screenshot is available.

Introduction

If you're familar with ArchGenXML and UML and have the products already installed you'll need around 7 minutes. Otherwise ~30 minutes should be enough.

Prepare your development-environment: Install Poseidon CE, ArchGenXML (installation instructions) (+ all its dependencies) and open a new UML in Poseidon.

Chcek out TemplateFields from Collective-SVN and install it in your zope instances Products directory.

The Goal

I want to show how simple one can subclass from ATDocument. In this example we're replacing the text-body field of ATDocument by a ZPTField from TemplateFields. Yes, indeed, PageTemplates as content are evil. Thats the reason why I called the Product EvilZPTDocument.

Paint the new type

Getting ATDocument into the model

  1. First paint a class in the diagram and name it ATDocument.
  2. Give the class a stereotypes <<stub>> and <<archetype>>, usually you need to add this stereotype first.
  3. Give the class a tagged-value import_from with value Products.ATContentTypes.content.document (for ancient ATContentTypes 0.2/Plone 2.0.x. you have to import_from Products.ATContentTypes.types.ATDocument).

Subclassing from ATDocument

  1. Paint another class and name it ZPTDocument.
  2. Paint an generelization arrow (the fat white one) from ZPTDocument to ATDocument by drag and drop.

Overrule the text field of ATDocument in ZPTDocument

  1. Add an attribute to class ZPTDocument and name it text.
  2. Give the text attribute the new Type (DataType) ZPTField.
  3. Add to the class ZPTDocument' a tagged value imports with value from Products.TemplateFields import ZPTField.
  4. Give the text attribute a tagged value widget:type with value TextAreaWidget .
  5. Give the text attribute a tagged value widget:label with value Page (ZPT).

Setting the view

  1. On class ZPTDocument set tagged values default_view and immediate_view both to value document_view.

Generate it

  1. Save the model as EvilZPTDocument.zuml.
  2. Fire up ArchGenXML::

    ./path/to/ArchGenXML.py path/to/EvilZPTDocument.zuml path/to/Zope/Instance/Products/EvilZPTDocument

  3. Restart your Zope.
  4. In Plone-Setup add your new Product to the your site.
  5. Add the new Page (ZPT) to your folder.
  6. The default PageTemplate provided in text field shows the page-title by default. Modify it to your needs and view how it renders.

Download

You may want to look at the finished model? Here I provide you with the model.

Filed under: