diff --git a/composer/instance.py b/composer/instance.py index 83c20e7..8eebcab 100644 --- a/composer/instance.py +++ b/composer/instance.py @@ -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): diff --git a/composer/interfaces.py b/composer/interfaces.py index 35e9707..b9d26d2 100644 --- a/composer/interfaces.py +++ b/composer/interfaces.py @@ -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 diff --git a/composer/schema/README.txt b/composer/schema/README.txt index 7e02a0f..bb33ad7 100644 --- a/composer/schema/README.txt +++ b/composer/schema/README.txt @@ -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. diff --git a/composer/schema/field.py b/composer/schema/field.py index ec36264..80ef663 100644 --- a/composer/schema/field.py +++ b/composer/schema/field.py @@ -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) diff --git a/composer/schema/instance.py b/composer/schema/instance.py index 62b243b..a44e4da 100644 --- a/composer/schema/instance.py +++ b/composer/schema/instance.py @@ -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: