
git-svn-id: svn://svn.cy55.de/Zope3/src/cybertools/trunk@2797 fd906abe-77d9-0310-91a1-e0d9ade77398
134 lines
3.6 KiB
Text
134 lines
3.6 KiB
Text
=========================================
|
|
Integrating objects from external systems
|
|
=========================================
|
|
|
|
Integration of external sources.
|
|
|
|
($Id$)
|
|
|
|
>>> from zope.app.testing.setup import placefulSetUp, placefulTearDown
|
|
>>> site = placefulSetUp(True)
|
|
|
|
Accessing Objects on a Remote BSCW Repository
|
|
=============================================
|
|
|
|
During testing we do not access a remote repository but just a dummy (fake)
|
|
repository for testing purposes.
|
|
|
|
>>> from cybertools.integrator.tests.bscw import BSCWServer, sampleObjects
|
|
>>> from cybertools.integrator.bscw import standardAttributes
|
|
>>> server = BSCWServer(sampleObjects)
|
|
|
|
>>> server.get_attributes('4', standardAttributes + ['containers'], 1, True)
|
|
[{...'name': 'public'...}, [{...'name': 'Introduction'...}]]
|
|
|
|
Access via read container and item/file proxies
|
|
-----------------------------------------------
|
|
|
|
Let's first register the proxy factory utilities.
|
|
|
|
>>> from zope import component
|
|
>>> from cybertools.integrator.bscw import ContainerFactory, ItemFactory, FileFactory
|
|
>>> component.provideUtility(ContainerFactory(), name='bscw')
|
|
>>> component.provideUtility(ItemFactory(), name='bscw')
|
|
>>> component.provideUtility(FileFactory(), name='bscw')
|
|
|
|
We can now access the root object of the BSCW repository.
|
|
|
|
>>> from cybertools.integrator.bscw import BSCWConnection
|
|
>>> connection = BSCWConnection('http://localhost/bscw.cgi/4',
|
|
... server=server)
|
|
|
|
>>> root = connection.getProxy()
|
|
>>> root
|
|
<...bscw.ReadContainer...>
|
|
|
|
>>> sorted(root.items())
|
|
[('bs_5', <...bscw.ReadContainer object...>)]
|
|
|
|
>>> root.address
|
|
'bs_4'
|
|
>>> root.internalPath
|
|
'bs_4'
|
|
>>> root.icon
|
|
'folder'
|
|
>>> root.properties
|
|
{...'name': 'public'...}
|
|
>>> root.title
|
|
'public'
|
|
>>> root.description
|
|
'Public Repository'
|
|
|
|
>>> str(root.externalURLInfo)
|
|
'http://localhost/bscw.cgi/4'
|
|
|
|
>>> list(root.parents)
|
|
[]
|
|
|
|
Let's also have a look at the item contained in the root object.
|
|
|
|
>>> bs_5 = root['bs_5']
|
|
>>> data = server.get_attributes('bs_5',
|
|
... ['__class__', 'type', 'id', 'name', 'descr', 'url_link'], 1, True)
|
|
|
|
>>> bs_5.items()
|
|
[('bs_6', <...bscw.File ...>), ('bs_7', <...bscw.Item ...>)]
|
|
>>> bs_5.address
|
|
'bs_5'
|
|
>>> bs_5.internalPath
|
|
'bs_5'
|
|
>>> bs_5.icon
|
|
'folder'
|
|
>>> bs_5.properties
|
|
{...'name': 'Introduction'...}
|
|
|
|
>>> str(bs_5.externalURLInfo)
|
|
'http://localhost/bscw.cgi/5'
|
|
|
|
>>> bs_5.properties['containers']
|
|
[{'name': 'public', '__id__': 'bs_4'}]
|
|
|
|
>>> [p.address for p in bs_5.parents]
|
|
['bs_4']
|
|
|
|
>>> bs_6 = bs_5['bs_6']
|
|
>>> [p.address for p in bs_6.parents]
|
|
['bs_5', 'bs_4']
|
|
|
|
|
|
The BSCW Repository View
|
|
========================
|
|
|
|
>>> site['bscw'] = connection
|
|
>>> bscwAccess = site['bscw']
|
|
|
|
>>> from cybertools.integrator.browser.bscw import BSCWView
|
|
>>> from zope.publisher.browser import TestRequest
|
|
>>> view = BSCWView(bscwAccess, TestRequest())
|
|
>>> view.baseUrl = 'http://localhost/bscw.cgi/'
|
|
>>> view.baseId = '4'
|
|
|
|
>>> items = list(view.content())
|
|
>>> items
|
|
[<...bscw.ItemView...>]
|
|
|
|
>>> items[0].url
|
|
'http://127.0.0.1/bscw?id=bs_5'
|
|
>>> items[0].icon
|
|
'http://127.0.0.1/++resource++folder.png'
|
|
|
|
>>> list(items[0].breadCrumbs)
|
|
[{'url': 'http://127.0.0.1/bscw?id=bs_4', 'title': 'public'},
|
|
{'url': 'http://127.0.0.1/bscw?id=bs_5', 'title': 'Introduction'}]
|
|
|
|
The top and the current level are not shown, otherwise we would get:
|
|
|
|
[{'url': 'http://127.0.0.1/bscw?id=bs_4', 'title': 'public'},
|
|
{'url': 'http://127.0.0.1/bscw?id=bs_5', 'title': 'Introduction'}]
|
|
|
|
|
|
Fin de partie
|
|
=============
|
|
|
|
>>> placefulTearDown()
|
|
|