allow schema processor plugin adapter

This commit is contained in:
Helmut Merz 2016-10-04 07:56:26 +02:00
parent b988ec0f32
commit 473dd10029
2 changed files with 19 additions and 4 deletions

View file

@ -1,5 +1,5 @@
# #
# Copyright (c) 2009 Helmut Merz helmutm@cy55.de # Copyright (c) 2016 Helmut Merz helmutm@cy55.de
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@ -26,7 +26,7 @@ from zope.interface import Interface
from zope import schema from zope import schema
from cybertools.composer.schema.field import Field from cybertools.composer.schema.field import Field
from cybertools.composer.schema.interfaces import ISchemaFactory from cybertools.composer.schema.interfaces import ISchemaFactory, ISchemaProcessor
from cybertools.composer.schema.schema import Schema from cybertools.composer.schema.schema import Schema
@ -70,6 +70,7 @@ class SchemaFactory(object):
def __init__(self, context): def __init__(self, context):
self.context = context self.context = context
self.schemaProcessor = ISchemaProcessor(self, None)
def __call__(self, interface, **kw): def __call__(self, interface, **kw):
fieldMapping = self.fieldMapping fieldMapping = self.fieldMapping
@ -84,7 +85,10 @@ class SchemaFactory(object):
field = interface[fname] field = interface[fname]
info = fieldMapping.get(field.__class__) info = fieldMapping.get(field.__class__)
f = createField(field, info) f = createField(field, info)
fields.append(f) if self.schemaProcessor is not None:
f = self.schemaProcessor.process(f, **kw)
if f is not None:
fields.append(f)
return Schema(name=interface.__name__, *fields, **kw) return Schema(name=interface.__name__, *fields, **kw)

View file

@ -1,5 +1,5 @@
# #
# Copyright (c) 2013 Helmut Merz helmutm@cy55.de # Copyright (c) 2016 Helmut Merz helmutm@cy55.de
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@ -73,6 +73,17 @@ class ISchemaFactory(Interface):
""" """
class ISchemaProcessor(Interface):
""" Interface for schema processor adapters.
"""
def process(field):
""" Process field according to specific processor data and
return modified field. Return None if field should not
be included in schema.
"""
class FieldType(SimpleTerm): class FieldType(SimpleTerm):
hidden = False hidden = False