plone / plone.supermodel

Provides XML import and export for schema interfaces based on zope.schema fields
5 stars 8 forks source link

Introduction

plone.supermodel provides XML import and export for schema interfaces based on zope.schema fields. The principal use cases are:

  1. Define a schema interface in code based on an XML file. This can be done with syntax like::

    from plone.supermodel import xmlSchema IMySchema = xmlSchema("myschema.xml")

  2. Save and load interface definitions via an XML format. To turn a schema interface into XML, you can do::

    from plone.supermodel import serializeSchema xml_string = serializeSchema(IMySchema)

To get a schema from an XML file, you can use the xmlSchema() function above, or you can use the more powerful spec() function, which turns a dict of all schemata and widget hints in a given XML file.

See schema.txt and interfaces.py in the source code for more information, including details on how to give widget hints for forms and how to keep multiple schemata in the same XML file.

Supermodel vs. Userschema

This package is quite similar to Tres Seaver's "userschema" library, which can be found at http://agendaless.com/Members/tseaver/software/userschema.

In fact, plone.supermodel was originally based on userschema. However, as the package was refined and refactored, less and less of userschema remained, to the point where we'd have needed to significantly refactor the latter to keep using it.

The XML import/export code is currently based on algorithms that were written for plone.app.portlets and plone.app.contentrules' GenericSetup handlers.

Some of the key differences between the two packages are:

In the future, it may be possible to make userschema reuse part of plone.supermodel or vice-a-versa, with more refactoring.