From 5e038c71e6edb3448d5e7a2b2de6599ede03edf2 Mon Sep 17 00:00:00 2001 From: helmutm Date: Tue, 6 Feb 2007 12:02:22 +0000 Subject: [PATCH] added XML-RPC method assignChild() git-svn-id: svn://svn.cy55.de/Zope3/src/loops/trunk@1572 fd906abe-77d9-0310-91a1-e0d9ade77398 --- xmlrpc/README.txt | 31 +++++++++++++++++++++++++++++-- xmlrpc/common.py | 11 +++++++++-- xmlrpc/configure.zcml | 3 ++- 3 files changed, 40 insertions(+), 5 deletions(-) diff --git a/xmlrpc/README.txt b/xmlrpc/README.txt index d905ba8..6e28a9b 100755 --- a/xmlrpc/README.txt +++ b/xmlrpc/README.txt @@ -11,6 +11,7 @@ Let's do some basic set up >>> from zope import component, interface >>> from zope.publisher.browser import TestRequest + >>> from loops.concept import Concept 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 @@ -19,7 +20,8 @@ ZCML setup): >>> from cybertools.relation.registry import DummyRelationRegistry >>> component.provideUtility(DummyRelationRegistry()) >>> from cybertools.relation.tests import IntIdsStub - >>> component.provideUtility(IntIdsStub()) + >>> intIds = IntIdsStub() + >>> component.provideUtility(intIds) >>> from loops.type import ConceptType, TypeConcept >>> component.provideAdapter(ConceptType) @@ -37,6 +39,23 @@ Let's look what setup has provided us with: >>> list(concepts) [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 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()) ['children', 'id', 'name', 'parents', 'title', '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: @@ -123,6 +142,14 @@ We can also retrieve children and parents explicitely: >>> sorted(p['name'] for p in pa[0]['objects']) [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 ============= diff --git a/xmlrpc/common.py b/xmlrpc/common.py index c94ce36..ddb224f 100644 --- a/xmlrpc/common.py +++ b/xmlrpc/common.py @@ -69,8 +69,8 @@ class LoopsMethods(MethodPublisher): def getPredicates(self): pt = self.concepts.getDefaultPredicate().conceptType - types = pt.getChildren((self.concepts.getTypePredicate(),)) - return [objectAsDict(t) for t in types] + preds = pt.getChildren((self.concepts.getTypePredicate(),)) + return [objectAsDict(p) for p in preds] def getChildren(self, id, predicates=[], child=''): obj = getObjectForUid(id) @@ -93,6 +93,13 @@ class LoopsMethods(MethodPublisher): obj.getParentRelations(), useSecond=False) 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): mapping = {'id': getUidForObject(obj), 'name': getName(obj), 'title': obj.title, diff --git a/xmlrpc/configure.zcml b/xmlrpc/configure.zcml index 11ae8aa..a452806 100644 --- a/xmlrpc/configure.zcml +++ b/xmlrpc/configure.zcml @@ -25,7 +25,8 @@ methods="getStartObject getObjectById getObjectByName getDefaultPredicate getTypePredicate getTypeConcept getConceptTypes getPredicates - getChildren getParents" + getChildren getParents + assignChild" permission="loops.xmlrpc.ManageConcepts" />