use IIndexAttributes adapter (if available) based on adapted object for text index on concept

git-svn-id: svn://svn.cy55.de/Zope3/src/loops/trunk@3215 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
helmutm 2009-02-07 16:28:07 +00:00
parent 529bdc7c1f
commit 3589363264
5 changed files with 62 additions and 4 deletions

View file

@ -401,16 +401,24 @@ class IndexAttributes(object):
def adapted(self):
return adapted(self.context)
@Lazy
def adaptedIndexAttributes(self):
if self.adapted != self.context:
return component.queryAdapter(self.adapted, IIndexAttributes)
return IIndexAttributes(self.adapted, None)
def text(self):
# TODO: use IIndexAttributes(self.adapted) if available
if self.adaptedIndexAttributes is not None:
return self.adaptedIndexAttributes.text()
description = self.context.description
if isinstance(description, I18NValue):
description = ' '.join(description.values())
actx = self.adapted
indexAttrs = getattr(actx, '_textIndexAttributes', ())
indexValues = [getattr(actx, attr, u'???') for attr in indexAttrs]
return ' '.join([self.title(), description] +
self.creators() +
[getattr(actx, attr, u'???') for attr in indexAttrs]).strip()
[c for c in self.creators() if c is not None] +
[v for v in indexValues if v is not None]).strip()
def title(self):
context = self.context
@ -419,6 +427,10 @@ class IndexAttributes(object):
title = ' '.join(title.values())
return ' '.join((getName(context), title)).strip()
def date(self):
if self.adaptedIndexAttributes is not None:
return self.adaptedIndexAttributes.date()
def creators(self):
cr = IZopeDublinCore(self.context).creators or []
pau = component.getUtility(IAuthentication)

View file

@ -387,6 +387,11 @@
name="text/rtf"
factory="cybertools.text.rtf.RtfTransform" />
<adapter for="loops.interfaces.ITextDocument"
provides="cybertools.text.interfaces.ITextTransform"
name="text/html"
factory="cybertools.text.html.HtmlTransform" />
<adapter for="loops.interfaces.IFile"
provides="cybertools.text.interfaces.ITextTransform"
name="application/vnd.ms-powerpoint"

View file

@ -520,6 +520,18 @@ class IndexAttributes(object):
self.context = context
def text(self):
actx = adapted(self.context)
txt = transformToText(actx)
if txt is not None:
return txt
if not actx.contentType.startswith('text'):
return u''
data = actx.data
if type(data) != unicode:
data = data.decode('UTF-8')
return data
def xx_text(self):
context = self.context
ti = IType(context).typeInterface
if ti is not None:
@ -559,6 +571,22 @@ class IndexAttributes(object):
def identifier(self):
return getName(self.context)
def transformToText(obj, data=None, contentType=None):
if data is None:
data = obj.data
if contentType is None:
contentType = obj.contentType
transform = component.queryAdapter(obj, ITextTransform, name=contentType)
if transform is not None:
#rfa = component.queryAdapter(IReadFile, obj)
rfa = IReadFile(obj, None)
if rfa is None:
if isinstance(data, unicode):
data = data.encode('UTF-8')
return transform(StringIO(data))
else:
return transform(rfa)
class ResourceTypeSourceList(object):
@ -577,4 +605,3 @@ class ResourceTypeSourceList(object):
def __len__(self):
return len(self.resourceTypes)

View file

@ -42,6 +42,7 @@ from cybertools.relation.interfaces import IRelationInvalidatedEvent
from cybertools.relation.registry import IndexableRelationAdapter
from cybertools.relation.registry import invalidateRelations, removeRelation
from cybertools.stateful.interfaces import IStatefulIndexInfo
from cybertools.text.html import HtmlTransform
from cybertools.typology.interfaces import IType
from loops.base import Loops
@ -169,6 +170,7 @@ class TestSite(object):
catalog['loops_state'] = KeywordIndex('tokens', IStatefulIndexInfo, False)
component.provideAdapter(ConceptIndexAttributes)
component.provideAdapter(ResourceIndexAttributes)
component.provideAdapter(HtmlTransform, (ITextDocument,), name='text/html')
component.provideAdapter(StatefulResourceIndexInfo)
component.provideHandler(handleTransition)

View file

@ -5,11 +5,17 @@ $Id$
"""
from zope import component
from zope.annotation.attribute import AttributeAnnotations
from zope.annotation.interfaces import IAnnotatable
from zope.app.catalog.catalog import Catalog
from zope.app.catalog.interfaces import ICatalog
from zope.app.catalog.field import FieldIndex
from zope.app.catalog.text import TextIndex
from zope.app.container.interfaces import IObjectRemovedEvent
from zope.app.security.interfaces import IAuthentication
from zope.app.security.principalregistry import principalRegistry
from zope.dublincore.annotatableadapter import ZDCAnnotatableAdapter
from zope.dublincore.interfaces import IZopeDublinCore
from cybertools.relation.tests import IntIdsStub
from cybertools.relation.registry import RelationRegistry
@ -20,8 +26,10 @@ from cybertools.typology.interfaces import IType
from loops.base import Loops
from loops import util
from loops.interfaces import IResource, IIndexAttributes
from loops.common import LoopsDCAdapter
from loops.concept import Concept
from loops.concept import IndexAttributes as ConceptIndexAttributes
from loops.interfaces import ILoopsObject, IConcept
from loops.resource import Resource
from loops.resource import IndexAttributes as ResourceIndexAttributes
from loops.knowledge.setup import SetupManager as KnowledgeSetupManager
@ -42,7 +50,11 @@ class TestSite(object):
relations = RelationRegistry()
relations.setupIndexes()
component.provideUtility(relations, IRelationRegistry)
component.provideUtility(principalRegistry, IAuthentication)
component.provideAdapter(IndexableRelationAdapter)
component.provideAdapter(ZDCAnnotatableAdapter, (ILoopsObject,), IZopeDublinCore)
component.provideAdapter(AttributeAnnotations, (ILoopsObject,))
component.provideAdapter(LoopsDCAdapter, (IConcept,), IZopeDublinCore)
component.provideAdapter(ConceptType)
component.provideAdapter(ResourceType)