allow schema processor plugin adapter
This commit is contained in:
parent
ef05da60e1
commit
d742b87c9c
2 changed files with 18 additions and 3 deletions
|
@ -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,6 +85,9 @@ 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)
|
||||||
|
if self.schemaProcessor is not None:
|
||||||
|
f = self.schemaProcessor.process(f)
|
||||||
|
if f is not None:
|
||||||
fields.append(f)
|
fields.append(f)
|
||||||
return Schema(name=interface.__name__, *fields, **kw)
|
return Schema(name=interface.__name__, *fields, **kw)
|
||||||
|
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Add table
Reference in a new issue