Provide typology stuff for concepts
git-svn-id: svn://svn.cy55.de/Zope3/src/loops/trunk@1120 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
		
							parent
							
								
									dfd398a401
								
							
						
					
					
						commit
						1adedb7b0e
					
				
					 3 changed files with 63 additions and 3 deletions
				
			
		|  | @ -237,6 +237,7 @@ | ||||||
|   <adapter factory="loops.resource.IndexableResource" /> |   <adapter factory="loops.resource.IndexableResource" /> | ||||||
|    |    | ||||||
|   <adapter factory="loops.type.ConceptType" /> |   <adapter factory="loops.type.ConceptType" /> | ||||||
|  |   <adapter factory="loops.type.ResourceType" /> | ||||||
|   <adapter factory="loops.type.LoopsTypeManager" /> |   <adapter factory="loops.type.LoopsTypeManager" /> | ||||||
|    |    | ||||||
|   <adapter factory="loops.external.NodesLoader" /> |   <adapter factory="loops.external.NodesLoader" /> | ||||||
|  |  | ||||||
							
								
								
									
										21
									
								
								helpers.txt
									
										
									
									
									
								
							
							
						
						
									
										21
									
								
								helpers.txt
									
										
									
									
									
								
							|  | @ -127,6 +127,24 @@ lazy properties, one should always get a new adapter: | ||||||
|   >>> cc1_type.typeProvider == topic |   >>> cc1_type.typeProvider == topic | ||||||
|   True |   True | ||||||
| 
 | 
 | ||||||
|  | Now let's have a look at resources. | ||||||
|  | 
 | ||||||
|  |   >>> from loops.interfaces import IResource | ||||||
|  |   >>> from loops.type import ResourceType | ||||||
|  |   >>> ztapi.provideAdapter(IResource, IType, ResourceType) | ||||||
|  | 
 | ||||||
|  |   >>> doc1_type = IType(doc1) | ||||||
|  |   >>> doc1_type.title | ||||||
|  |   u'Document' | ||||||
|  |   >>> doc1_type.token | ||||||
|  |   '.loops/resources/document' | ||||||
|  |   >>> doc1_type.tokenForSearch | ||||||
|  |   'loops:resource:document' | ||||||
|  |    | ||||||
|  |   >>> img1_type = IType(img1) | ||||||
|  |   >>> img1_type.title | ||||||
|  |   u'Media Asset' | ||||||
|  | 
 | ||||||
| Can we find out somehow which types are available? This is the time to look | Can we find out somehow which types are available? This is the time to look | ||||||
| for a type manager. This could be a utility; but in the loops package it | for a type manager. This could be a utility; but in the loops package it | ||||||
| is again an adapter, now for the loops root object. Nevertheless one can | is again an adapter, now for the loops root object. Nevertheless one can | ||||||
|  | @ -142,7 +160,8 @@ get a type manager from all loops objects, always with the same context: | ||||||
| 
 | 
 | ||||||
|   >>> types = typeManager.types |   >>> types = typeManager.types | ||||||
|   >>> sorted(t.token for t in types) |   >>> sorted(t.token for t in types) | ||||||
|   ['.loops/concepts/topic', '.loops/concepts/type'] |   ['.loops/concepts/topic', '.loops/concepts/type', | ||||||
|  |    '.loops/resources/document', '.loops/resources/mediaasset'] | ||||||
| 
 | 
 | ||||||
|   >>> typeManager.getType('.loops/concepts/topic') == cc1_type |   >>> typeManager.getType('.loops/concepts/topic') == cc1_type | ||||||
|   True |   True | ||||||
|  |  | ||||||
							
								
								
									
										44
									
								
								type.py
									
										
									
									
									
								
							
							
						
						
									
										44
									
								
								type.py
									
										
									
									
									
								
							|  | @ -26,7 +26,8 @@ from zope.app import zapi | ||||||
| from zope.component import adapts | from zope.component import adapts | ||||||
| from zope.cachedescriptors.property import Lazy | from zope.cachedescriptors.property import Lazy | ||||||
| from cybertools.typology.type import BaseType, TypeManager | from cybertools.typology.type import BaseType, TypeManager | ||||||
| from loops.interfaces import ILoopsObject, IConcept | from loops.interfaces import ILoopsObject, IConcept, IResource | ||||||
|  | from loops.resource import Document, MediaAsset | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| class LoopsType(BaseType): | class LoopsType(BaseType): | ||||||
|  | @ -71,6 +72,43 @@ class ConceptType(LoopsType): | ||||||
|         return self.context.conceptType |         return self.context.conceptType | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | class ResourceType(LoopsType): | ||||||
|  | 
 | ||||||
|  |     adapts(IResource) | ||||||
|  | 
 | ||||||
|  |     typeTitles = {'MediaAsset': u'Media Asset'} | ||||||
|  | 
 | ||||||
|  |     @Lazy | ||||||
|  |     def title(self): | ||||||
|  |         cn = self.className | ||||||
|  |         return self.typeTitles.get(cn, unicode(cn)) | ||||||
|  | 
 | ||||||
|  |     @Lazy | ||||||
|  |     def token(self): | ||||||
|  |         cn = self.className | ||||||
|  |         return '/'.join(('.loops/resources', cn.lower(),)) | ||||||
|  | 
 | ||||||
|  |     @Lazy | ||||||
|  |     def tokenForSearch(self): | ||||||
|  |         cn = self.className | ||||||
|  |         return ':'.join(('loops:resource', cn.lower(),)) | ||||||
|  | 
 | ||||||
|  |     @Lazy | ||||||
|  |     def className(self): | ||||||
|  |         return self.context.__class__.__name__ | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | class ResourceTypeInfo(ResourceType): | ||||||
|  | 
 | ||||||
|  |     def __init__(self, cls): | ||||||
|  |         self.cls = cls | ||||||
|  | 
 | ||||||
|  |     @Lazy | ||||||
|  |     def className(self): | ||||||
|  |         return self.cls.__name__ | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| class LoopsTypeManager(TypeManager): | class LoopsTypeManager(TypeManager): | ||||||
| 
 | 
 | ||||||
|     adapts(ILoopsObject) |     adapts(ILoopsObject) | ||||||
|  | @ -88,6 +126,8 @@ 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) | ||||||
|         return tuple(LoopsTypeInfo(c) for c in result) |         cTypes = [LoopsTypeInfo(c) for c in result] | ||||||
|  |         rTypes = [ResourceTypeInfo(cls) for cls in (Document, MediaAsset)] | ||||||
|  |         return tuple(cTypes + rTypes) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 helmutm
						helmutm