How to avoid silly duplication errors when creating new content types?
forsberg at efod.se
Mon Oct 22 16:09:56 UTC 2007
I've been doing ugly plone hacks for several years, but now I decided
to learn how to do it the right way, so I bought Aspeli's book
(Professional Plone Development), and it has been my companion for
many happy hours. Good stuff!
I followed the chapter about creating your own content types and
created two content types for my own needs. However, being a big fan of
the DRY (Don't Repeat Yourself) principle, I find the many places you
have to add for example the name of a product a bit scary.
Let's say that you want to add a new content type to your existing
package. Making a quick check, I find that you have to change the
* (toplevel) __init__.py to define an add permission in ADD_PERMISSIONS
* interfaces.py to define the interface of the new type.
* profiles/default/factorytool.xml to define that the new type should
be handled by the factory tool.
* profiles/default/rolemap.xml for security settings.
- object name.
* content/<typename>.py to define the actual Archetypes class.
On top of this, all fields in a new content type should be defined in
the interface, in the AT schema and preferably (at least according to
the book), as "bridges" between AT fields and python properties, to
allow non-generated code to use fields in a natural way. That's _three_
Lot's of places where especially beginners can make mistakes. For
example, I had forgotten to change the name of the factory in my
<typename>.xml (copied the file from the example file in the book's
source code package) - with the effect that the content type didn't
appear in the list of addable types in the folder I tried to add it to.
Although I would enjoy if there were fewer places to change when I add
a new type, I understand that each location have its purpose. This
leads to the question on how to avoid making the mistakes - are there
for example any tools that can help in making sure everything is in sync?
How do people with more experience solve this problem?
Erik Forsberg http://efod.se
GPG/PGP Key: 1024D/0BAC89D9
More information about the Product-Developers