work in progress: composer.schema
git-svn-id: svn://svn.cy55.de/Zope3/src/cybertools/trunk@1747 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
parent
8ec1876315
commit
36f0f335ce
5 changed files with 15 additions and 11 deletions
|
@ -31,7 +31,7 @@ class Instance(object):
|
|||
|
||||
implements(IInstance)
|
||||
|
||||
templateKey = 'composer.template'
|
||||
aspect = 'composer.default'
|
||||
|
||||
def __init__(self, context):
|
||||
self.context = context
|
||||
|
@ -39,11 +39,11 @@ class Instance(object):
|
|||
|
||||
def setTemplate(self, template):
|
||||
templates = getattr(self.context, '__templates__', {})
|
||||
templates.setdefault(self.templateKey, template)
|
||||
templates.setdefault(self.aspect, template)
|
||||
self.context.__templates__ = templates
|
||||
def getTemplate(self):
|
||||
templates = getattr(self.context, '__templates__', {})
|
||||
return templates.get(self.templateKey, None)
|
||||
return templates.get(self.aspect, None)
|
||||
template = property(getTemplate, setTemplate)
|
||||
|
||||
def applyTemplate(self, *args, **kw):
|
||||
|
|
|
@ -63,6 +63,8 @@ class IInstance(Interface):
|
|||
|
||||
context = Attribute('Object this instance adapter has been created for')
|
||||
template = Attribute('The template to be used for this instance')
|
||||
aspect = Attribute('A dotted name that helps to store and retrieve the '
|
||||
'template.')
|
||||
|
||||
def applyTemplate(*args, **kw):
|
||||
""" Apply the template using the instance's context. Note that this
|
||||
|
|
|
@ -10,11 +10,11 @@ Schema and Field Management
|
|||
We start with setting up a schema with fields.
|
||||
|
||||
>>> serviceSchema = Schema()
|
||||
>>> serviceSchema.components.append(Field('title'))
|
||||
>>> serviceSchema.components.append(Field('description'))
|
||||
>>> serviceSchema.components.append(Field('start'))
|
||||
>>> serviceSchema.components.append(Field('end'))
|
||||
>>> serviceSchema.components.append(Field('capacity'))
|
||||
>>> serviceSchema.components.append(Field(u'title'))
|
||||
>>> serviceSchema.components.append(Field(u'description'))
|
||||
>>> serviceSchema.components.append(Field(u'start'))
|
||||
>>> serviceSchema.components.append(Field(u'end'))
|
||||
>>> serviceSchema.components.append(Field(u'capacity'))
|
||||
|
||||
For using a schema we need some class that we can use for creating
|
||||
objects.
|
||||
|
|
|
@ -23,15 +23,17 @@ $Id$
|
|||
"""
|
||||
|
||||
from zope.interface import implements
|
||||
from zope import schema
|
||||
|
||||
from cybertools.composer.base import Component, Element, Compound
|
||||
from cybertools.composer.base import Template
|
||||
|
||||
|
||||
class Field(Component):
|
||||
class Field(Component, schema.Field):
|
||||
|
||||
def __init__(self, name, title=None, **kw):
|
||||
assert name
|
||||
self.name = self.__name__ = name
|
||||
self.title = title is None and name or title
|
||||
title = title is None and name or title
|
||||
super(Field, self).__init__(title, __name__=name, **kw)
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ from cybertools.composer.instance import Instance
|
|||
|
||||
class Editor(Instance):
|
||||
|
||||
templateKey = 'schema.editor'
|
||||
aspect = 'schema.editor.default'
|
||||
|
||||
def applyTemplate(self, data={}, *args, **kw):
|
||||
for c in self.template.components:
|
||||
|
|
Loading…
Add table
Reference in a new issue