use 'qualifiers' attribute
git-svn-id: svn://svn.cy55.de/Zope3/src/loops/trunk@1123 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
parent
628e81b740
commit
b39e7548b8
2 changed files with 37 additions and 5 deletions
14
helpers.txt
14
helpers.txt
|
@ -108,7 +108,7 @@ So let's check the type of the type object:
|
||||||
>>> type_type.tokenForSearch
|
>>> type_type.tokenForSearch
|
||||||
'loops:concept:type'
|
'loops:concept:type'
|
||||||
>>> type_type.qualifiers
|
>>> type_type.qualifiers
|
||||||
('concept', 'system',)
|
('concept',)
|
||||||
|
|
||||||
Now we register another type ('topic') and assign it to cc1:
|
Now we register another type ('topic') and assign it to cc1:
|
||||||
|
|
||||||
|
@ -144,6 +144,8 @@ Now let's have a look at resources.
|
||||||
'.loops/resources/document'
|
'.loops/resources/document'
|
||||||
>>> doc1_type.tokenForSearch
|
>>> doc1_type.tokenForSearch
|
||||||
'loops:resource:document'
|
'loops:resource:document'
|
||||||
|
>>> doc1_type.qualifiers
|
||||||
|
('resource',)
|
||||||
|
|
||||||
>>> img1_type = IType(img1)
|
>>> img1_type = IType(img1)
|
||||||
>>> img1_type.title
|
>>> img1_type.title
|
||||||
|
@ -170,6 +172,16 @@ get a type manager from all loops objects, always with the same context:
|
||||||
>>> typeManager.getType('.loops/concepts/topic') == cc1_type
|
>>> typeManager.getType('.loops/concepts/topic') == cc1_type
|
||||||
True
|
True
|
||||||
|
|
||||||
|
The listTypes() method allows us to select types that fulfill a certain
|
||||||
|
condition:
|
||||||
|
|
||||||
|
>>> types = typeManager.listTypes(include=('concept',))
|
||||||
|
>>> sorted(t.token for t in types)
|
||||||
|
['.loops/concepts/topic', '.loops/concepts/type']
|
||||||
|
>>> types = typeManager.listTypes(exclude=('concept',))
|
||||||
|
>>> sorted(t.token for t in types)
|
||||||
|
['.loops/resources/document', '.loops/resources/mediaasset']
|
||||||
|
|
||||||
Index attributes adapter
|
Index attributes adapter
|
||||||
------------------------
|
------------------------
|
||||||
|
|
||||||
|
|
28
type.py
28
type.py
|
@ -67,17 +67,27 @@ class ConceptType(LoopsType):
|
||||||
|
|
||||||
adapts(IConcept)
|
adapts(IConcept)
|
||||||
|
|
||||||
|
qualifiers = ('concept',)
|
||||||
|
|
||||||
@Lazy
|
@Lazy
|
||||||
def typeProvider(self):
|
def typeProvider(self):
|
||||||
return self.context.conceptType
|
return self.context.conceptType
|
||||||
|
|
||||||
|
|
||||||
|
class ConceptTypeInfo(ConceptType):
|
||||||
|
|
||||||
|
def __init__(self, typeProvider):
|
||||||
|
self.typeProvider = self.context = typeProvider
|
||||||
|
|
||||||
|
|
||||||
class ResourceType(LoopsType):
|
class ResourceType(LoopsType):
|
||||||
|
|
||||||
adapts(IResource)
|
adapts(IResource)
|
||||||
|
|
||||||
typeTitles = {'MediaAsset': u'Media Asset'}
|
typeTitles = {'MediaAsset': u'Media Asset'}
|
||||||
|
|
||||||
|
qualifiers = ('resource',)
|
||||||
|
|
||||||
@Lazy
|
@Lazy
|
||||||
def title(self):
|
def title(self):
|
||||||
cn = self.className
|
cn = self.className
|
||||||
|
@ -118,6 +128,17 @@ class LoopsTypeManager(TypeManager):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def types(self):
|
def types(self):
|
||||||
|
return self.conceptTypes() + self.resourceTypes()
|
||||||
|
|
||||||
|
def listTypes(self, include=None, exclude=None):
|
||||||
|
for t in self.types:
|
||||||
|
if include and not [q for q in t.qualifiers if q in include]:
|
||||||
|
continue
|
||||||
|
if exclude and [q for q in t.qualifiers if q in exclude]:
|
||||||
|
continue
|
||||||
|
yield t
|
||||||
|
|
||||||
|
def conceptTypes(self):
|
||||||
cm = self.context.getConceptManager()
|
cm = self.context.getConceptManager()
|
||||||
to = cm.getTypeConcept()
|
to = cm.getTypeConcept()
|
||||||
tp = cm.getTypePredicate()
|
tp = cm.getTypePredicate()
|
||||||
|
@ -126,8 +147,7 @@ class LoopsTypeManager(TypeManager):
|
||||||
result = to.getChildren([tp])
|
result = to.getChildren([tp])
|
||||||
if to not in result:
|
if to not in result:
|
||||||
result.append(to)
|
result.append(to)
|
||||||
cTypes = [LoopsTypeInfo(c) for c in result]
|
return tuple([ConceptTypeInfo(c) for c in result])
|
||||||
rTypes = [ResourceTypeInfo(cls) for cls in (Document, MediaAsset)]
|
|
||||||
return tuple(cTypes + rTypes)
|
|
||||||
|
|
||||||
|
|
||||||
|
def resourceTypes(self):
|
||||||
|
return tuple([ResourceTypeInfo(cls) for cls in (Document, MediaAsset)])
|
||||||
|
|
Loading…
Add table
Reference in a new issue