Source

nimrud / conex / src / conex / types / zcml.py

Full commit
from zope.component import getUtility
from conex.types.interfaces import IConcaveTypesFactory        
from zope.interface import Interface
from zope.configuration.fields import GlobalObject
from zope.schema import TextLine 


class IContentTypeDirective(Interface):
    """Defines the schema for the Nimrud Content Type directive
    in ZCML"""
    schema = TextLine(
        title=u"Schema",
        description=u"A dotted path to the type's schema, be it XML or python",
        required=True)

    implementation = GlobalObject(
        title=u"Implementation class",
        description=u"The class that implements the schema, if one exists.",
        required=False)

def _register(schema, implementation=None):
    factory = getUtility(IConcaveTypesFactory, u"conex.TypesFactory")
    factory.register_type(schema, implementation)

def register_type(_context, schema, implementation=None):

    _context.action(
        discriminator=schema,
        callable=_register,
        args=(schema, implementation,)
        )