added XML-RPC method assignChild()

git-svn-id: svn://svn.cy55.de/Zope3/src/loops/trunk@1572 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
helmutm 2007-02-06 12:02:22 +00:00
parent 7cfd866670
commit 5e038c71e6
3 changed files with 40 additions and 5 deletions

View file

@ -11,6 +11,7 @@ Let's do some basic set up
>>> from zope import component, interface >>> from zope import component, interface
>>> from zope.publisher.browser import TestRequest >>> from zope.publisher.browser import TestRequest
>>> from loops.concept import Concept
and setup a simple loops site with a concept manager and some concepts and setup a simple loops site with a concept manager and some concepts
(with all the type machinery, what in real life is done via standard (with all the type machinery, what in real life is done via standard
@ -19,7 +20,8 @@ ZCML setup):
>>> from cybertools.relation.registry import DummyRelationRegistry >>> from cybertools.relation.registry import DummyRelationRegistry
>>> component.provideUtility(DummyRelationRegistry()) >>> component.provideUtility(DummyRelationRegistry())
>>> from cybertools.relation.tests import IntIdsStub >>> from cybertools.relation.tests import IntIdsStub
>>> component.provideUtility(IntIdsStub()) >>> intIds = IntIdsStub()
>>> component.provideUtility(intIds)
>>> from loops.type import ConceptType, TypeConcept >>> from loops.type import ConceptType, TypeConcept
>>> component.provideAdapter(ConceptType) >>> component.provideAdapter(ConceptType)
@ -37,6 +39,23 @@ Let's look what setup has provided us with:
>>> list(concepts) >>> list(concepts)
[u'file', u'hasType', u'image', u'predicate', u'standard', u'textdocument', u'type'] [u'file', u'hasType', u'image', u'predicate', u'standard', u'textdocument', u'type']
Now let's add a few more concepts:
>>> topic = concepts[u'topic'] = Concept()
>>> topic.title = u'Topic'
>>> intIds.register(topic)
7
>>> zope = concepts[u'zope'] = Concept()
>>> zope.conceptType = topic
>>> zope.title = u'Zope'
>>> intIds.register(zope)
8
>>> zope3 = concepts[u'zope3'] = Concept()
>>> zope3.conceptType = topic
>>> zope3.title = u'Zope 3'
>>> intIds.register(zope3)
9
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: top-level type concept:
@ -57,7 +76,7 @@ If we provide a concept named "domain" this will be used as starting point:
>>> 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']
('7', u'domain', u'Domain', '0') ('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:
@ -123,6 +142,14 @@ We can also retrieve children and parents explicitely:
>>> sorted(p['name'] for p in pa[0]['objects']) >>> sorted(p['name'] for p in pa[0]['objects'])
[u'predicate'] [u'predicate']
Updating the concept map
------------------------
>>> zopeId = xrf.getObjectByName('zope')['id']
>>> zope3Id = xrf.getObjectByName('zope3')['id']
>>> xrf.assignChild(zopeId, zope3Id, defaultPred['id'])
'OK'
Fin de partie Fin de partie
============= =============

View file

@ -69,8 +69,8 @@ class LoopsMethods(MethodPublisher):
def getPredicates(self): def getPredicates(self):
pt = self.concepts.getDefaultPredicate().conceptType pt = self.concepts.getDefaultPredicate().conceptType
types = pt.getChildren((self.concepts.getTypePredicate(),)) preds = pt.getChildren((self.concepts.getTypePredicate(),))
return [objectAsDict(t) for t in types] return [objectAsDict(p) for p in preds]
def getChildren(self, id, predicates=[], child=''): def getChildren(self, id, predicates=[], child=''):
obj = getObjectForUid(id) obj = getObjectForUid(id)
@ -93,6 +93,13 @@ class LoopsMethods(MethodPublisher):
obj.getParentRelations(), useSecond=False) obj.getParentRelations(), useSecond=False)
return mapping return mapping
def assignChild(self, objId, predicateId, childId):
obj = getObjectForUid(objId)
pred = getObjectForUid(predicateId)
child = getObjectForUid(childId)
obj.assignChild(child, pred)
return 'OK'
def objectAsDict(obj): def objectAsDict(obj):
mapping = {'id': getUidForObject(obj), 'name': getName(obj), 'title': obj.title, mapping = {'id': getUidForObject(obj), 'name': getName(obj), 'title': obj.title,

View file

@ -25,7 +25,8 @@
methods="getStartObject getObjectById getObjectByName methods="getStartObject getObjectById getObjectByName
getDefaultPredicate getTypePredicate getTypeConcept getDefaultPredicate getTypePredicate getTypeConcept
getConceptTypes getPredicates getConceptTypes getPredicates
getChildren getParents" getChildren getParents
assignChild"
permission="loops.xmlrpc.ManageConcepts" permission="loops.xmlrpc.ManageConcepts"
/> />