How to subclass an ATContentType in 7 Minutes

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.

Attached files

error in tagged value in evilzptpage.zuml model

Posted by David Bain at May 04, 2006 06:15 PM
I noticed that in the attached evilzptpage.zuml the class ZPTDocument has a tagged value 'suppl_views' set to python:(). This needs to be changed to be completely empty.

so instead of::

  suppl_views | python:()

change it to::

  suppl_views |




suppl_views and xmi

Posted by Aaron Turner at Jan 30, 2008 01:13 PM
I also noticed that the xmi file for the tutorial fails with ArchGenXML 1.5.2. However I can't find any explicit line in the XMI that matches suppl_views | python:() to remove it.

Unfortunately the XMI also fails to import into ArgoUML, which is a shame as that is both free and it is possible to add the required sterotype set for working with Plone.

So far with the failure to generate with ArchGenXML and even with test projects from ArchGenXML failing to appear in the list of installable products in Plone 3.0.5 the process is not proving to be the relatively simple UML-driven procedure I had hoped for.

Poseidon

Posted by Aaron Turner at Jan 30, 2008 01:26 PM
It seems that running the model through an evaluation version of Poseidon and editing there did the trick with suppl_views issue.

Very good tutorial

Posted by Bryan White at Jun 02, 2006 04:56 AM
While very short, this tutorial was very specific throughout and as such was very helpful to me, getting back into ArchGenXML and Plone after a nine or so month break. I really did like that from required software to specific tagged values on objects, the tutorial was so exact about the process.

Thanks!

Adding stereotypes to a model in Poseidon

Posted by John Habermann at Dec 21, 2006 01:49 AM
As someone who had never used a UML tool before trying out this tutorial I found it took some time to figure out how to add a sterotype to a class in Poseidon. I thought I would add the steps here for others in the same situation. This is based on the community edition 5.0

Steps are:

1. Click on your class in the Diagram Pane

2. In the Details Pane, which is under the main diagram pane the "Properties" tab should be selected. In the left hand navigation of this pane, scroll to the bottom. You will see "Stereotypes (0)" listed.

3. Right click on stereotypes and select "Set stereotypes". The "Select needed elements" window should open.

4. Enter the stereotype you want to set for you class in the "Add" box and click on the "Add" button. That will add these stereotypes into the list of available stereotypes.

5. Select the stereotypes and use the ">>" button to add it to the selected Stereotypes window. Select any other stereotypes that you want to add to your class.

The archetypes will now appear in your class diagram above the title.