Supermodel handler
==================
This package contains a handler for the ``marshal`` ``plone.supermodel``
namespace, which can be used to mark the primary field of a schema.
This handler is installed so long as ``plone.supermodel`` is installed.
First, let's load this package's ZCML so that we can run the tests:
>>> configuration = """\
...
...
...
...
...
...
...
... """
>>> from StringIO import StringIO
>>> from zope.configuration import xmlconfig
>>> xmlconfig.xmlconfig(StringIO(configuration))
Next, let's define a sample model that exercises the 'marshal' attribute.
>>> schema = """\
...
...
...
...
... title
...
...
... Body
...
...
...
... """
We can load this using plone.supermodel:
>>> from plone.supermodel import loadString
>>> model = loadString(schema)
The ``body`` field should now be marked with the ``IPrimaryField`` marker:
>>> from plone.rfc822.interfaces import IPrimaryField
>>> schema = model.schema
>>> IPrimaryField.providedBy(schema['title'])
False
>>> IPrimaryField.providedBy(schema['body'])
True
Naturally, we can also write out the primary field attribute from an interface
on which it is marked:
>>> from zope.interface import Interface, alsoProvides
>>> from zope import schema
>>> class ITestSchema(Interface):
... title = schema.TextLine(title=u"Title")
... body = schema.Text(title=u"Body")
>>> alsoProvides(ITestSchema['body'], IPrimaryField)
>>> from plone.supermodel import serializeSchema
>>> print serializeSchema(ITestSchema) # doctest: +NORMALIZE_WHITESPACE
Title
Body