moved client stuff to composer.schema

git-svn-id: svn://svn.cy55.de/Zope3/src/cybertools/trunk@1848 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
helmutm 2007-07-29 14:35:43 +00:00
parent 242c4a4921
commit f8be0e1a0f
4 changed files with 117 additions and 2 deletions

View file

@ -58,7 +58,7 @@ class ITemplate(Interface):
# instances
class IInstance(Interface):
""" Represents (adapts) an object that uses a template.
""" Represents (adapts) an object (a client) that uses a template.
"""
context = Attribute('Object this instance adapter has been created for')

51
composer/schema/client.py Normal file
View file

@ -0,0 +1,51 @@
#
# Copyright (c) 2007 Helmut Merz helmutm@cy55.de
#
# 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
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
"""
Client implementations.
$Id$
"""
from zope.component import adapts
from zope.interface import implements
from cybertools.composer.schema.interfaces import IClient
from cybertools.composer.schema.interfaces import IClientManager, IClientFactory
class Client(object):
implements(IClient)
def __init__(self, manager):
self.manager = manager
class ClientFactory(object):
implements(IClientFactory)
adapts(IClientManager)
def __init__(self, context):
self.context = context
def __call__(self):
return Client(self.context)

View file

@ -17,14 +17,18 @@
#
"""
Client classes for schemas.
Instance adapter classes for schemas.
$Id$
"""
from BTrees.OOBTree import OOBTree
from zope.component import adapts
from zope.interface import implements
from cybertools.composer.instance import Instance
from cybertools.composer.interfaces import IInstance
from cybertools.composer.schema.interfaces import IClient
class Editor(Instance):
@ -39,3 +43,34 @@ class Editor(Instance):
# or directly use request...
print c.name, getattr(self.context, c.name, '-')
class ClientInstanceAdapter(object):
implements(IInstance)
adapts(IClient)
baseAspect = 'schema.client.'
schema = 'default'
@property
def aspect(self):
return self.baseAspect + self.schema
@property
def template(self):
return self.context.manager.clientSchemas.get(self.schema, None)
def __init__(self, context):
self.context = context
def applyTemplate(self, data={}, schema='default', **kw):
if getattr(self.context, 'attributes', None) is None:
self.context.attributes = OOBTree()
self.schema = schema
template = self.template
attributes = self.context.attributes.setdefault(self.aspect, OOBTree())
if template is not None:
for c in template.components:
name = c.name
attributes[name] = data.get(name, u'')

View file

@ -73,3 +73,32 @@ class IField(IComponent):
description=_(u'Must a value been entered into this field?'),
required=False,)
# clients
class IClient(Interface):
""" An fairly abstract interface for objects to be used as clients
for other objects (e.g. services).
"""
manager = Attribute('The object that cares for this client.')
class IClientFactory(Interface):
""" Creates client objects.
"""
def __call__():
""" Creates and returns a client object.
"""
class IClientManager(Interface):
""" Cares for a client typically providing schemas.
"""
clientSchemas = Attribute('A collection of schema objects '
'that describe the data fields of the client '
'objects.')