Plone 3 Products Development Cookbook
上QQ阅读APP看书,第一时间看更新

Installing the product

Congratulations! You have created your first Archetypes-based content type.

Let's add it in our already configured Zope instance to see what it looks like.

Instead of using the ArchGenXML product as it is, we will wrap it in an egg structure and install it in the src folder of our buildout.

How to do it…

First of all, we must create the egg structure that will hold the ArchGenXML generated code:

  1. Go to your buildout folder and create — if not created yet — a src folder.
    mkdir ./src
    
  2. Then call paster to create the egg folder structure:
    paster create -t plone 
    

It will start a very short wizard to select some options for our product. Most important is the first one:

Add whatever you want to the remaining options or just hit Enter to each one.

Once finished, paster should have created a folder structure like:

Products.poxContentTypes

+ docs

+ Products

+ poxContentTypes

...

- __init__.py

+ Products.poxContentTypes.egg-info

- dependency_links.txt

...

- README.txt

- setup.cfg

- setup.py

The new egg product is empty, but we already have some code that ArchGenXML has generated. So let's use it to make things work.

  1. Copy all the contents of ./models/poxContentTypes inside your ArchGenXML folder, (not the poxContentTypes folder itself, but its contents) into the src/Products.poxContentTypes/Products/poxContentTypes folder inside your buildout folder. Some of the existing files will be overwritten, don't worry about them.

    We are done! We have a working content type. Now we should tell our Zope instance to be aware of it. To do that, modify the buildout and build the instance again.

  2. In the main [buildout] part, modify the eggs parameter by adding a new line:
    [buildout]
    
    ...
    
    eggs = 
    
    ...
    
     Products.poxContentTypes
    
  3. Given that our product is in development stage (that is, it's inside the src folder of our instance), we must also change the develop parameter to tell our instance where to fetch its code from:
    [buildout]
    
    ...
    
    develop = 
     src/Products.poxContentTypes
    
  4. Build your instance again and re-launch it:
    ./bin/buildout
    ./bin/instance fg
    

How it works…

Unfortunately, ArchGenXML doesn't create the egg structure together with the product. Neither does it allow us to use arbitrary namespaces. This is why we have chosen a simple word for the package name: poxContentTypes that will be preceded by the Zope-ish Products to create the final namespace: Products.poxContentTypes.

Note

If you choose a dotted package name, ArchGenXML will automatically replace the dots by underscores in the final product namespace.

Nevertheless we can still use ArchGenXML’s power to generate the necessary code and insert it into an egg structure we create ad-hoc with paster .