Some Links

Tutorials

License

Plone with Schemas

“Using Dexterity to extend and customise Plone”

Last month, you tried Plone 4 and could create a schema
interactively. However, at present, it does not seem to be possible
to convert the interactive definitions into code. So, this month you
will explore how to add code for two schemas which are related and
create a simple custom view for displaying them.

You may wish to install Plone as a non-root user. In which case,
the installation is in $HOME/Plone. The advantage, of course, is that
you will not need to be a superuser for the development activities.

Once Plone 4 is installed, your next step is to modify the
buildout configuration files to add the needed components.

Zopeskel is defined is base.cfg. You will need to add the
egg for zopeskel.dexterity and needed dependencies. Your zopeskel
section on base.cfg should now look like:

You may want to change the default behaviour so that the system
does not add metadata fields like title. This is achieved by deleting
the line below from lfy.demo.department.xml and
lfy.demo.writer.xml in profiles/default/types
sub-directory.

<element value="plone.app.dexterity.behaviors.metadata.IBasic"/>

You are now ready to build the Plone instance with the custom
fields. Edit buildout.cfg file to add lfy.demo egg:

eggs =

...

lfy.demo

develop =

src/lfy.demo

Stop plone, build the new instance and
start it again.

$ bin/plonectl stop

$ bin/buildout

$ bin/plonectl start

As an admin user, enable Dexterity types and the demo application
you have just created in the 'Add-ons' from 'Site
Preferences'. 'Add new' option will now have Department
and Writer as additional types.

Changing the View

The default view is reasonable but each field is stacked below the
other. A URL is shown as text and not as a link. You can replace the
default view of the writer by your own custom view.

In writer.py, in the class 'SampleView' un-comment
the following line:

grok.name('view')

Now, SampleView becomes the default view. You will need to
modify the corresponding template, sampleview.pt, in the
sub-directory writer_templates. The template's logic is in the
metal:main block, which you may replace as follows so that the
profile wraps around the image:

The hardest part in the template is to display the image. Since
the image is stored in the database, it has to be constructed into a
URL and the img tag with src attribute created. Context
refers to the current object, which will normally be followed by an
attribute. The attribute may be followed by an operation of the
attribute. The image and the uri are conditionally shown if the
respective objects exist.

As profile is a rich text object, “output”
method converts it into html text. The “structure” option
tells the system to use it as it is without escaping any characters.
You can learn more about TAL and METAL at
http://docs.zope.org/zope2/zope2book/AppendixC.html.

It's not just the templates, the code can also be as complex as
you need. Virtually anything you can do with grok, you should be able
to do in Plone. So, you have a powerful tool to create a site whose
primary but not exclusive focus is content management.