We'll start with the example I described in the previous section, a simple quotation content type. When an object based off the content type is added, text fields for the speaker of the quotation and the quotation will be presented. After they are filled out and the form is submitted, the object will be created. When the object is viewed, it will display the speaker and the quotation. Create a folder called Quotation in the Products directory. This is where we'll store our content type's files. The first file we will create is config.py. This defines some constants that we'll use throughout our content type: from Products.CMFCore.CMFCorePermissions import AddPortalContent In config.py, we first define the permission required to manipulate our content type. Since our content type really isn't anything special, we just assign it to the generic AddPortalContent permission. We then define a constant called GLOBALS, which is used during the installation of our content type. Finally, we give our content type (or project/product, rather, since it's possible to have multiple content types in the same package) a name. Next, we'll have to create our content type's schema, which will define the fields associated with the content type. When we edit quotations, we'll want a text field for the speaker and a larger text area for the quotation itself. All of this is specified in the schema: from Products.Archetypes.public import * The first thing we do is create our content type's schema. We create two text fields, one for the speaker and one for the quotation. Both are required to be filled out. The second one is also set to a text area. Next, we create the content type's class, where we simply copy the schema, and, finally, we register the content type. Next is __init__.py, where we glue what we've done so far together: from config import * Besides importing our configuration file and various methods that we'll be using, the first thing we do is define a function and import our Quotation.py file. From there, we get some information about our package, the content types associated with it, constructors and factory type information, in that order. We then create a utils.ContentInit with this information, along with the package name and the permission we defined in config.py. Finally, we have to create Install.py, which is responsible for installing our product. Create a folder called Extensions inside Quotation to place the install script in: from Products.Archetypes.Extensions.utils import installTypes This simply installs our content type and inserts a short message into the installation log. Our Quotation content type is now complete. Restart Zope and then install the product in the “Add/Remove Products” section of Plone. You should now be able to add an object based off our content type to a folder. You can also create the files version.txt and README.txt. The contents of the former file will be added to the product's name, and the contents of the latter file will be displayed as the product's description.
blog comments powered by Disqus |