extend setup: additional types, remove image
git-svn-id: svn://svn.cy55.de/Zope3/src/loops/trunk@1634 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
		
							parent
							
								
									a45f2311f0
								
							
						
					
					
						commit
						3e62f36022
					
				
					 6 changed files with 49 additions and 52 deletions
				
			
		|  | @ -215,7 +215,7 @@ class ConceptManager(BTreeContainer): | ||||||
| 
 | 
 | ||||||
|     def getDefaultPredicate(self): |     def getDefaultPredicate(self): | ||||||
|         if self.defaultPredicate is None: |         if self.defaultPredicate is None: | ||||||
|             self.defaultPredicate = self['standard'] |             self.defaultPredicate = self.get('standard') | ||||||
|         return self.defaultPredicate |         return self.defaultPredicate | ||||||
| 
 | 
 | ||||||
|     def getPredicateType(self): |     def getPredicateType(self): | ||||||
|  |  | ||||||
							
								
								
									
										25
									
								
								helpers.txt
									
										
									
									
									
								
							
							
						
						
									
										25
									
								
								helpers.txt
									
										
									
									
									
								
							|  | @ -236,9 +236,10 @@ 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/file', '.loops/concepts/image', '.loops/concepts/predicate', |   ['.loops/concepts/domain', '.loops/concepts/file', | ||||||
|      '.loops/concepts/textdocument', '.loops/concepts/topic', |    '.loops/concepts/predicate', '.loops/concepts/query', | ||||||
|      '.loops/concepts/type'] |    '.loops/concepts/textdocument', '.loops/concepts/topic', | ||||||
|  |    '.loops/concepts/type'] | ||||||
| 
 | 
 | ||||||
|   >>> typeManager.getType('.loops/concepts/topic') == cc1_type |   >>> typeManager.getType('.loops/concepts/topic') == cc1_type | ||||||
|   True |   True | ||||||
|  | @ -248,11 +249,11 @@ condition: | ||||||
| 
 | 
 | ||||||
|   >>> types = typeManager.listTypes(include=('concept',)) |   >>> types = typeManager.listTypes(include=('concept',)) | ||||||
|   >>> sorted(t.token for t in types) |   >>> sorted(t.token for t in types) | ||||||
|   ['.loops/concepts/predicate', '.loops/concepts/topic', '.loops/concepts/type'] |   ['.loops/concepts/domain', '.loops/concepts/predicate', | ||||||
|  |    '.loops/concepts/query', '.loops/concepts/topic', '.loops/concepts/type'] | ||||||
|   >>> types = typeManager.listTypes(exclude=('concept',)) |   >>> types = typeManager.listTypes(exclude=('concept',)) | ||||||
|   >>> sorted(t.token for t in types) |   >>> sorted(t.token for t in types) | ||||||
|   ['.loops/concepts/file', '.loops/concepts/image', |   ['.loops/concepts/file', '.loops/concepts/textdocument'] | ||||||
|    '.loops/concepts/textdocument'] |  | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| Type-based interfaces and adapters | Type-based interfaces and adapters | ||||||
|  | @ -313,14 +314,12 @@ Concepts as queries | ||||||
| ------------------- | ------------------- | ||||||
| 
 | 
 | ||||||
| We first have to set up the query type, i.e. a type concept associated | We first have to set up the query type, i.e. a type concept associated | ||||||
| with the IQueryConcept interface: | with the IQueryConcept interface. The query type concept itself has already | ||||||
|  | been provided by the setup, but we have to register a corresponding adapter. | ||||||
| 
 | 
 | ||||||
|   >>> from loops.query import IQueryConcept, QueryConcept |   >>> from loops.query import QueryConcept | ||||||
|   >>> component.provideAdapter(QueryConcept, (IConcept,), IQueryConcept) |   >>> component.provideAdapter(QueryConcept) | ||||||
| 
 |   >>> query = concepts['query'] | ||||||
|   >>> query = concepts['query'] = Concept(u'Query') |  | ||||||
|   >>> query.conceptType = typeObject |  | ||||||
|   >>> ITypeConcept(query).typeInterface = IQueryConcept |  | ||||||
| 
 | 
 | ||||||
| Next we need a concept of this type: | Next we need a concept of this type: | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -34,8 +34,9 @@ ZCML setup): | ||||||
| 
 | 
 | ||||||
| Let's look what setup has provided us with: | Let's look what setup has provided us with: | ||||||
| 
 | 
 | ||||||
|   >>> list(concepts) |   >>> sorted(concepts) | ||||||
|   [u'file', u'hasType', u'image', u'predicate', u'standard', u'textdocument', u'type'] |   [u'domain', u'file', u'hasType', u'note', u'predicate', u'query', | ||||||
|  |    u'standard', u'textdocument', u'type'] | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| loops Traversal | loops Traversal | ||||||
|  | @ -54,14 +55,14 @@ returns a REST view of the object. | ||||||
|   >>> component.provideAdapter(ConceptView) |   >>> component.provideAdapter(ConceptView) | ||||||
| 
 | 
 | ||||||
| Navigation typically starts at a start object, which by default ist the | Navigation typically starts at a start object, which by default ist the | ||||||
| top-level type concept: | domain type concept (or the top-level type concept, if there is no domain type): | ||||||
| 
 | 
 | ||||||
|   >>> request = TestRequest() |   >>> request = TestRequest() | ||||||
|   >>> obj = LoopsTraverser(loopsRoot, request).publishTraverse(request, 'startObject') |   >>> obj = LoopsTraverser(loopsRoot, request).publishTraverse(request, 'startObject') | ||||||
|   >>> obj |   >>> obj | ||||||
|   <loops.rest.common.ConceptView object at ...> |   <loops.rest.common.ConceptView object at ...> | ||||||
|   >>> obj.context.title |   >>> obj.context.title | ||||||
|   u'Type' |   u'Domain' | ||||||
| 
 | 
 | ||||||
| The traversal adapter returns a view that when called renders the | The traversal adapter returns a view that when called renders the | ||||||
| representation of its context object: | representation of its context object: | ||||||
|  |  | ||||||
|  | @ -37,9 +37,9 @@ ZCML setup): | ||||||
|   >>> typeConcept = concepts['type'] |   >>> typeConcept = concepts['type'] | ||||||
| 
 | 
 | ||||||
|   >>> from loops.concept import Concept |   >>> from loops.concept import Concept | ||||||
|   >>> query = concepts['query'] = Concept(u'Query') |  | ||||||
|   >>> topic = concepts['topic'] = Concept(u'Topic') |   >>> topic = concepts['topic'] = Concept(u'Topic') | ||||||
|   >>> for c in (query, topic): c.conceptType = typeConcept |   >>> for c in (topic,): c.conceptType = typeConcept | ||||||
|  |   >>> query = concepts['query'] | ||||||
| 
 | 
 | ||||||
| In addition we create a concept that holds the search page and a node | In addition we create a concept that holds the search page and a node | ||||||
| (page) that links to this concept: | (page) that links to this concept: | ||||||
|  | @ -84,7 +84,7 @@ zcml in real life: | ||||||
| 
 | 
 | ||||||
|   >>> t = searchView.conceptTypesForSearch() |   >>> t = searchView.conceptTypesForSearch() | ||||||
|   >>> len(t) |   >>> len(t) | ||||||
|   3 |   4 | ||||||
|   >>> t.getTermByToken('loops:concept:*').title |   >>> t.getTermByToken('loops:concept:*').title | ||||||
|   'Any Concept' |   'Any Concept' | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
							
								
								
									
										17
									
								
								setup.py
									
										
									
									
									
								
							
							
						
						
									
										17
									
								
								setup.py
									
										
									
									
									
								
							|  | @ -28,8 +28,10 @@ from zope import component | ||||||
| from zope.component import adapts | from zope.component import adapts | ||||||
| from zope.interface import implements, Interface | from zope.interface import implements, Interface | ||||||
| 
 | 
 | ||||||
| from loops.interfaces import ILoops, ITypeConcept, IFile, IImage, ITextDocument | from loops.interfaces import ILoops, ITypeConcept | ||||||
|  | from loops.interfaces import IFile, IImage, ITextDocument, INote | ||||||
| from loops.concept import ConceptManager, Concept | from loops.concept import ConceptManager, Concept | ||||||
|  | from loops.query import IQueryConcept | ||||||
| from loops.resource import ResourceManager | from loops.resource import ResourceManager | ||||||
| from loops.view import ViewManager, Node | from loops.view import ViewManager, Node | ||||||
| 
 | 
 | ||||||
|  | @ -73,16 +75,21 @@ class SetupManager(object): | ||||||
|         hasType = self.addObject(conceptManager, Concept, 'hasType', title=u'has Type') |         hasType = self.addObject(conceptManager, Concept, 'hasType', title=u'has Type') | ||||||
|         predicate = self.addObject(conceptManager, Concept, 'predicate', title=u'Predicate') |         predicate = self.addObject(conceptManager, Concept, 'predicate', title=u'Predicate') | ||||||
|         standard = self.addObject(conceptManager, Concept, 'standard', title=u'subobject') |         standard = self.addObject(conceptManager, Concept, 'standard', title=u'subobject') | ||||||
|  |         domain = self.addObject(conceptManager, Concept, 'domain', title=u'Domain') | ||||||
|  |         query = self.addObject(conceptManager, Concept, 'query', title=u'Query') | ||||||
|         file = self.addObject(conceptManager, Concept, 'file', title=u'File') |         file = self.addObject(conceptManager, Concept, 'file', title=u'File') | ||||||
|         image = self.addObject(conceptManager, Concept, 'image', title=u'Image') |         #image = self.addObject(conceptManager, Concept, 'image', title=u'Image') | ||||||
|         textdocument = self.addObject(conceptManager, Concept, |         textdocument = self.addObject(conceptManager, Concept, | ||||||
|                                       'textdocument', title=u'Text Document') |                                       'textdocument', title=u'Text') | ||||||
|         for c in (typeConcept, file, image, textdocument, predicate): |         note = self.addObject(conceptManager, Concept, 'note', title=u'Note') | ||||||
|  |         for c in (typeConcept, domain, query, file, textdocument, predicate): | ||||||
|             c.conceptType = typeConcept |             c.conceptType = typeConcept | ||||||
|         ITypeConcept(typeConcept).typeInterface = ITypeConcept |         ITypeConcept(typeConcept).typeInterface = ITypeConcept | ||||||
|  |         ITypeConcept(query).typeInterface = IQueryConcept | ||||||
|         ITypeConcept(file).typeInterface = IFile |         ITypeConcept(file).typeInterface = IFile | ||||||
|         ITypeConcept(image).typeInterface = IImage |         #ITypeConcept(image).typeInterface = IImage | ||||||
|         ITypeConcept(textdocument).typeInterface = ITextDocument |         ITypeConcept(textdocument).typeInterface = ITextDocument | ||||||
|  |         ITypeConcept(note).typeInterface = INote | ||||||
|         hasType.conceptType = predicate |         hasType.conceptType = predicate | ||||||
|         standard.conceptType = predicate |         standard.conceptType = predicate | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -36,25 +36,26 @@ ZCML setup): | ||||||
| 
 | 
 | ||||||
| Let's look what setup has provided us with: | Let's look what setup has provided us with: | ||||||
| 
 | 
 | ||||||
|   >>> list(concepts) |   >>> sorted(concepts) | ||||||
|   [u'file', u'hasType', u'image', u'predicate', u'standard', u'textdocument', u'type'] |   [u'domain', u'file', u'hasType', u'note', u'predicate', u'query', | ||||||
|  |    u'standard', u'textdocument', u'type'] | ||||||
| 
 | 
 | ||||||
| Now let's add a few more concepts: | Now let's add a few more concepts: | ||||||
| 
 | 
 | ||||||
|   >>> topic = concepts[u'topic'] = Concept(u'Topic') |   >>> topic = concepts[u'topic'] = Concept(u'Topic') | ||||||
|   >>> intIds.register(topic) |   >>> intIds.register(topic) | ||||||
|   7 |   8 | ||||||
|   >>> zope = concepts[u'zope'] = Concept(u'Zope') |   >>> zope = concepts[u'zope'] = Concept(u'Zope') | ||||||
|   >>> zope.conceptType = topic |   >>> zope.conceptType = topic | ||||||
|   >>> intIds.register(zope) |   >>> intIds.register(zope) | ||||||
|   8 |   9 | ||||||
|   >>> zope3 = concepts[u'zope3'] = Concept(u'Zope 3') |   >>> zope3 = concepts[u'zope3'] = Concept(u'Zope 3') | ||||||
|   >>> zope3.conceptType = topic |   >>> zope3.conceptType = topic | ||||||
|   >>> intIds.register(zope3) |   >>> intIds.register(zope3) | ||||||
|   9 |   10 | ||||||
| 
 | 
 | ||||||
| Navigation typically starts at a start object, which by default ist the | Navigation typically starts at a start object, which by default ist the | ||||||
| top-level type concept: | domain concept (if present, otherwise the top-level type concept): | ||||||
| 
 | 
 | ||||||
|   >>> from loops.xmlrpc.common import LoopsMethods |   >>> from loops.xmlrpc.common import LoopsMethods | ||||||
|   >>> xrf = LoopsMethods(loopsRoot, TestRequest()) |   >>> xrf = LoopsMethods(loopsRoot, TestRequest()) | ||||||
|  | @ -62,27 +63,16 @@ top-level type concept: | ||||||
|   >>> sorted(startObj.keys()) |   >>> sorted(startObj.keys()) | ||||||
|   ['children', 'id', 'name', 'parents', 'title', 'type'] |   ['children', 'id', 'name', 'parents', 'title', 'type'] | ||||||
|   >>> startObj['id'], startObj['name'], startObj['title'], startObj['type'] |   >>> startObj['id'], startObj['name'], startObj['title'], startObj['type'] | ||||||
|   ('0', u'type', u'Type', '0') |   ('1', u'domain', u'Domain', '0') | ||||||
| 
 |  | ||||||
| If we provide a concept named "domain" this will be used as starting point: |  | ||||||
| 
 |  | ||||||
|   >>> from loops.concept import Concept |  | ||||||
|   >>> domain = concepts[u'domain'] = Concept(u'Domain') |  | ||||||
|   >>> domain.conceptType = concepts.getTypeConcept() |  | ||||||
|   >>> startObj = xrf.getStartObject() |  | ||||||
|   >>> sorted(startObj.keys()) |  | ||||||
|   ['children', 'id', 'name', 'parents', 'title', 'type'] |  | ||||||
|   >>> startObj['id'], startObj['name'], startObj['title'], startObj['type'] |  | ||||||
|   ('10', u'domain', u'Domain', '0') |  | ||||||
| 
 | 
 | ||||||
| There are a few standard objects we can retrieve directly: | There are a few standard objects we can retrieve directly: | ||||||
| 
 | 
 | ||||||
|   >>> defaultPred = xrf.getDefaultPredicate() |   >>> defaultPred = xrf.getDefaultPredicate() | ||||||
|   >>> defaultPred['id'], defaultPred['name'] |   >>> defaultPred['id'], defaultPred['name'] | ||||||
|   ('6', u'standard') |   ('7', u'standard') | ||||||
|   >>> typePred = xrf.getTypePredicate() |   >>> typePred = xrf.getTypePredicate() | ||||||
|   >>> typePred['id'], typePred['name'] |   >>> typePred['id'], typePred['name'] | ||||||
|   ('5', u'hasType') |   ('6', u'hasType') | ||||||
|   >>> typeConcept = xrf.getTypeConcept() |   >>> typeConcept = xrf.getTypeConcept() | ||||||
|   >>> typeConcept['id'], typeConcept['name'] |   >>> typeConcept['id'], typeConcept['name'] | ||||||
|   ('0', u'type') |   ('0', u'type') | ||||||
|  | @ -90,7 +80,7 @@ There are a few standard objects we can retrieve directly: | ||||||
| In addition we can get a list of all types and all predicates available: | In addition we can get a list of all types and all predicates available: | ||||||
| 
 | 
 | ||||||
|   >>> sorted(t['name'] for t in xrf.getConceptTypes()) |   >>> sorted(t['name'] for t in xrf.getConceptTypes()) | ||||||
|   [u'domain', u'file', u'image', u'predicate', u'textdocument', u'type'] |   [u'domain', u'file', u'predicate', u'query', u'textdocument', u'type'] | ||||||
|   >>> sorted(t['name'] for t in xrf.getPredicates()) |   >>> sorted(t['name'] for t in xrf.getPredicates()) | ||||||
|   [u'hasType', u'standard'] |   [u'hasType', u'standard'] | ||||||
| 
 | 
 | ||||||
|  | @ -98,10 +88,10 @@ We can also retrieve a certain object by its id or its name: | ||||||
| 
 | 
 | ||||||
|   >>> obj2 = xrf.getObjectById('2') |   >>> obj2 = xrf.getObjectById('2') | ||||||
|   >>> obj2['id'], obj2['name'] |   >>> obj2['id'], obj2['name'] | ||||||
|   ('2', u'image') |   ('2', u'query') | ||||||
|   >>> textdoc = xrf.getObjectByName(u'textdocument') |   >>> textdoc = xrf.getObjectByName(u'textdocument') | ||||||
|   >>> textdoc['id'], textdoc['name'] |   >>> textdoc['id'], textdoc['name'] | ||||||
|   ('3', u'textdocument') |   ('4', u'textdocument') | ||||||
| 
 | 
 | ||||||
| All methods that retrieve one object also returns its children and parents: | All methods that retrieve one object also returns its children and parents: | ||||||
| 
 | 
 | ||||||
|  | @ -111,7 +101,7 @@ All methods that retrieve one object also returns its children and parents: | ||||||
|   >>> ch[0]['name'] |   >>> ch[0]['name'] | ||||||
|   u'hasType' |   u'hasType' | ||||||
|   >>> sorted(c['name'] for c in ch[0]['objects']) |   >>> sorted(c['name'] for c in ch[0]['objects']) | ||||||
|   [u'domain', u'file', u'image', u'predicate', u'textdocument', u'type'] |   [u'domain', u'file', u'predicate', u'query', u'textdocument', u'type'] | ||||||
| 
 | 
 | ||||||
|   >>> pa = defaultPred['parents'] |   >>> pa = defaultPred['parents'] | ||||||
|   >>> len(pa) |   >>> len(pa) | ||||||
|  | @ -129,7 +119,7 @@ We can also retrieve children and parents explicitely: | ||||||
|   >>> ch[0]['name'] |   >>> ch[0]['name'] | ||||||
|   u'hasType' |   u'hasType' | ||||||
|   >>> sorted(c['name'] for c in ch[0]['objects']) |   >>> sorted(c['name'] for c in ch[0]['objects']) | ||||||
|   [u'domain', u'file', u'image', u'predicate', u'textdocument', u'type'] |   [u'domain', u'file', u'predicate', u'query', u'textdocument', u'type'] | ||||||
| 
 | 
 | ||||||
|   >>> pa = xrf.getParents('6') |   >>> pa = xrf.getParents('6') | ||||||
|   >>> len(pa) |   >>> len(pa) | ||||||
|  | @ -152,7 +142,7 @@ Updating the concept map | ||||||
| 
 | 
 | ||||||
|   >>> topicId = xrf.getObjectByName('topic')['id'] |   >>> topicId = xrf.getObjectByName('topic')['id'] | ||||||
|   >>> xrf.createConcept(topicId, u'zope2', u'Zope 2') |   >>> xrf.createConcept(topicId, u'zope2', u'Zope 2') | ||||||
|   {'title': u'Zope 2', 'type': '7', 'id': '12', 'name': u'zope2'} |   {'title': u'Zope 2', 'type': '8', 'id': '12', 'name': u'zope2'} | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| Fin de partie | Fin de partie | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 helmutm
						helmutm