How to subclass an ATContentType in 7 Minutes
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
- First paint a class in the diagram and name it
ATDocument. - Give the class a stereotypes
<<stub>>and<<archetype>>, usually you need to add this stereotype first. - Give the class a tagged-value
import_fromwith valueProducts.ATContentTypes.content.document(for ancient ATContentTypes 0.2/Plone 2.0.x. you have to import_from Products.ATContentTypes.types.ATDocument).
Subclassing from ATDocument
- Paint another class and name it
ZPTDocument. - Paint an generelization arrow (the fat white one) from ZPTDocument to ATDocument by drag and drop.
Overrule the text field of ATDocument in ZPTDocument
- Add an attribute to class ZPTDocument and name it
text. - Give the text attribute the new Type (DataType)
ZPTField. - Add to the class ZPTDocument' a tagged value
importswith valuefrom Products.TemplateFields import ZPTField. - Give the text attribute a tagged value
widget:typewith valueTextAreaWidget. - Give the text attribute a tagged value
widget:labelwith valuePage (ZPT).
Setting the view
- On class ZPTDocument set tagged values
default_viewandimmediate_viewboth to valuedocument_view.
Generate it
- Save the model as
EvilZPTDocument.zuml. - Fire up ArchGenXML::
./path/to/ArchGenXML.py path/to/EvilZPTDocument.zuml path/to/Zope/Instance/Products/EvilZPTDocument
- Restart your Zope.
- In Plone-Setup add your new Product to the your site.
- Add the new
Page (ZPT)to your folder. - The default PageTemplate provided in
textfield 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.
