diff --git a/browser/configure.zcml b/browser/configure.zcml index b7aa99b..40f90df 100644 --- a/browser/configure.zcml +++ b/browser/configure.zcml @@ -580,14 +580,6 @@ permission="zope.ManageContent" /> - - - @@ -402,6 +401,11 @@ + + + + diff --git a/resource.py b/resource.py index 72a7b34..9b9bf87 100644 --- a/resource.py +++ b/resource.py @@ -375,8 +375,8 @@ class TextDocumentAdapter(DocumentAdapter): """ A type adapter for providing text document functionality for resources. """ - implements(IDocument) - _contextAttributes = list(IDocument) + list(IBaseResource) + implements(ITextDocument) + _contextAttributes = list(ITextDocument) + list(IBaseResource) class NoteAdapter(DocumentAdapter): diff --git a/schema.py b/schema.py new file mode 100644 index 0000000..1325f25 --- /dev/null +++ b/schema.py @@ -0,0 +1,62 @@ +# +# Copyright (c) 2005 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 +# + +""" +Specialized schema factories + +$Id$ +""" + +from zope.component import adapts + +from cybertools.composer.schema.factory import SchemaFactory +from loops.interfaces import IResourceAdapter, IFile, INote + + +class ResourceSchemaFactory(SchemaFactory): + + adapts(IResourceAdapter) + + def __call__(self, interface, **kw): + schema = super(ResourceSchemaFactory, self).__call__(interface, **kw) + schema.fields.data.height = 10 + return schema + + +class FileSchemaFactory(SchemaFactory): + + adapts(IFile) + + def __call__(self, interface, **kw): + schema = super(FileSchemaFactory, self).__call__(interface, **kw) + if 'request' in kw and kw['request'].principal.id != 'rootadmin': + del schema.fields['contentType'] + return schema + + +class NoteSchemaFactory(SchemaFactory): + + adapts(INote) + + def __call__(self, interface, **kw): + schema = super(NoteSchemaFactory, self).__call__(interface, **kw) + del schema.fields['description'] + schema.fields.data.height = 5 + return schema + + diff --git a/tests/setup.py b/tests/setup.py index d11758d..391d036 100644 --- a/tests/setup.py +++ b/tests/setup.py @@ -16,6 +16,7 @@ from zope.app.security.interfaces import IAuthentication from zope.dublincore.annotatableadapter import ZDCAnnotatableAdapter from zope.dublincore.interfaces import IZopeDublinCore +from cybertools.composer.schema.factory import SchemaFactory from cybertools.composer.schema.field import FieldInstance, NumberFieldInstance from cybertools.composer.schema.instance import Instance, Editor from cybertools.relation.tests import IntIdsStub @@ -34,6 +35,7 @@ from loops.concept import Concept from loops.concept import IndexAttributes as ConceptIndexAttributes from loops.resource import Resource, FileAdapter from loops.resource import IndexAttributes as ResourceIndexAttributes +from loops.schema import ResourceSchemaFactory, FileSchemaFactory, NoteSchemaFactory from loops.setup import SetupManager, addObject from loops.type import LoopsType, ConceptType, ResourceType, TypeConcept @@ -67,6 +69,11 @@ class TestSite(object): component.provideAdapter(FieldInstance) component.provideAdapter(NumberFieldInstance, name='number') + component.provideAdapter(SchemaFactory) + component.provideAdapter(ResourceSchemaFactory) + component.provideAdapter(FileSchemaFactory) + component.provideAdapter(NoteSchemaFactory) + component.getSiteManager().registerHandler(invalidateRelations, (ILoopsObject, IObjectRemovedEvent)) component.getSiteManager().registerHandler(removeRelation,