Changeset 1355
- Timestamp:
- 08/08/08 00:48:52 (4 months ago)
- Files:
-
- pleiades.workspace/trunk/pleiades/workspace/browser/kml.py (modified) (3 diffs)
- pleiades.workspace/trunk/pleiades/workspace/browser/xml.py (modified) (2 diffs)
- pleiades.workspace/trunk/pleiades/workspace/configure.zcml (modified) (1 diff)
- pleiades.workspace/trunk/pleiades/workspace/content/workspace.py (modified) (2 diffs)
- pleiades.workspace/trunk/pleiades/workspace/event.py (added)
- pleiades.workspace/trunk/pleiades/workspace/interfaces.py (modified) (2 diffs)
- pleiades.workspace/trunk/pleiades/workspace/profiles/default/types/Workspace.xml (modified) (2 diffs)
- pleiades.workspace/trunk/pleiades/workspace/setuphandlers.py (added)
- pleiades.workspace/trunk/pleiades/workspace/tests/base.py (modified) (1 diff)
- pleiades.workspace/trunk/pleiades/workspace/tests/factory.txt (modified) (1 diff)
- pleiades.workspace/trunk/pleiades/workspace/tests/kml-import.txt (modified) (1 diff)
- pleiades.workspace/trunk/pleiades/workspace/tests/test_doctest.py (modified) (2 diffs)
- pleiades.workspace/trunk/pleiades/workspace/tests/xml-import.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
pleiades.workspace/trunk/pleiades/workspace/browser/kml.py
r1294 r1355 6 6 from elementtree import ElementTree as etree 7 7 import keytree 8 from pleiades.workspace.interfaces import IResource 9 8 10 9 11 class KMLImporter(BrowserView): … … 15 17 request = self.request 16 18 response = self.request.response 17 18 places = self.context['places'] 19 names = self.context['names'] 20 locations = self.context['locations'] 21 19 portal = getToolByName(self.context, 'portal_url').getPortalObject() 22 20 ptool = getToolByName(self.context, 'plone_utils') 23 21 22 places = portal['places'] 23 names = portal['names'] 24 locations = portal['locations'] 25 24 26 savepoint = transaction.savepoint() 25 26 27 try: 27 28 k = etree.fromstring(request.file.read()) … … 55 56 a.addReference(names[nid], 'hasName') 56 57 a.addReference(locations[lid], 'hasLocation') 58 59 # Attach to workspace 60 IResource(names[nid]).attach(self.context) 61 IResource(locations[lid]).attach(self.context) 62 IResource(places[pid]).attach(self.context) 63 57 64 except: 58 65 savepoint.rollback() pleiades.workspace/trunk/pleiades/workspace/browser/xml.py
r1313 r1355 1 #from Acquisition import aq_inner 1 import glob 2 from os.path import basename 3 from elementtree import ElementTree as etree 2 4 import transaction 3 5 from Products.Five.browser import BrowserView 4 6 from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile 5 7 from Products.CMFCore.utils import getToolByName 6 from elementtree import ElementTree as etree7 8 import keytree 8 from Products.PleiadesEntity.Extensions.loader import loaden 9 from Products.PleiadesEntity.Extensions.loader import load_place 10 from pleiades.workspace.interfaces import IResource 9 11 10 12 … … 16 18 def __call__(self): 17 19 request = self.request 18 return loaden(self.context, request.form['sourcedir']) 20 sourcedir = request.form.get('sourcedir', None) 21 portal = getToolByName(self.context, 'portal_url').getPortalObject() 22 places = portal['places'] 23 names = portal['names'] 24 locations = portal['locations'] 25 failures = [] 26 count = 0 27 for xml in glob.glob("%s/*.xml" % sourcedir): 28 try: 29 result = load_place(portal, xml) 30 for nid in result['name_ids']: 31 IResource(names[nid]).attach(self.context) 32 for lid in result['location_ids']: 33 IResource(locations[lid]).attach(self.context) 34 IResource(places[result['place_id']]).attach(self.context) 35 count += 1 36 except Exception, e: 37 failures.append([basename(xml), str(e)]) 38 39 if len(failures) == 0: 40 return "Loaded %d of %d files." % (count, count) 41 else: 42 msg = "Loaded %d of %d files. Failures:\n" % (count, count + len(failures)) 43 for f in failures: 44 msg += "%s\n" % str(f) 45 return msg 19 46 20 47 pleiades.workspace/trunk/pleiades/workspace/configure.zcml
r1287 r1355 11 11 <include package=".content" /> 12 12 13 <adapter 14 factory=".resource.Resource" 15 for="Products.PleiadesEntity.content.Location.Location" 16 trusted="true" 17 /> 18 19 <adapter 20 factory=".resource.Resource" 21 for="Products.PleiadesEntity.content.Name.Name" 22 trusted="true" 23 /> 24 25 <adapter 26 factory=".resource.Resource" 27 for="Products.PleiadesEntity.content.Place.Place" 28 trusted="true" 29 /> 30 31 <subscriber 32 handler=".event.reindexDocSubscriber" 33 for=".event.IResourceModifiedEvent" 34 /> 35 36 <class class=".resource.Resource"> 37 <require 38 permission="zope.View" 39 interface=".interfaces.IResource" 40 /> 41 </class> 42 13 43 <genericsetup:registerProfile 14 44 name="default" pleiades.workspace/trunk/pleiades/workspace/content/workspace.py
r1288 r1355 1 """Definition of the CinemaFolder content type and associated schemata and2 other logic.3 4 This file contains a number of comments explaining the various lines of5 code. Other files in this sub-package contain analogous code, but will6 not be commented as heavily.7 8 Please see README.txt for more information on how the content types in9 this package are used.10 """11 12 1 from zope.interface import implements 13 2 from zope.component import adapter, getMultiAdapter, getUtility … … 94 83 text = atapi.ATFieldProperty('text') 95 84 85 def initTopic(self, oid, type): 86 topic = self[oid] 87 c = topic.addCriterion('pleiades_wsuids', 'ATSelectionCriterion') 88 c.setValue(self.UID()) 89 c = topic.addCriterion('Type', 'ATPortalTypeCriterion') 90 c.setValue(type) 91 96 92 def initializeArchetype(self, **kwargs): 97 self['places'] = PlaceContainer('places') 98 self['locations'] = LocationContainer('locations') 99 self['names'] = folder.ATFolder('names') 93 tid = self.invokeFactory('Topic', id='locations', title='Locations') 94 self.initTopic(tid, 'Location') 95 tid = self.invokeFactory('Topic', id='names', title='Names') 96 self.initTopic(tid, 'Name') 97 tid = self.invokeFactory('Topic', id='places', title='Places') 98 self.initTopic(tid, 'Place') 100 99 101 100 # This line tells Archetypes about the content type pleiades.workspace/trunk/pleiades/workspace/interfaces.py
r1327 r1355 1 from zope.interface import Interface 1 from zope.interface import Interface, Attribute 2 2 from zope import schema 3 3 … … 5 5 6 6 from pleiades.workspace import WorkspaceMessageFactory as _ 7 8 9 class IResource(Interface): 10 11 def attach(workspace): 12 """Attach object to a workspace.""" 13 14 def detach(workspace): 15 """Detach object from a workspace.""" 16 17 wsuids = Attribute("List of workspace UIDs") 18 7 19 8 20 class IWorkspace(Interface): pleiades.workspace/trunk/pleiades/workspace/profiles/default/types/Workspace.xml
r1288 r1355 41 41 <property name="immediate_view">atct_edit</property> 42 42 43 <!-- global_allow specifies whether the object is generally addable. If44 this is False, only those folders that set filter_content_types to45 True and includes the portal_type of this object in the list of46 allowed_content_types will allow creation of this type. Here,47 we let cinema folders be addable in normal folders (provided the48 user has the appropriate permissions, of course). We then explicitly49 filter the content types allowed inside a Cinema Folder, restricting50 them to Cinema, Promotion and other nested Cinema Folders. Of course,51 this can be changed in the ZODB later.52 -->53 43 <property name="global_allow">True</property> 54 44 <property name="filter_content_types">True</property> … … 57 47 <element value="Location Container" /> 58 48 <element value="Folder" /> 49 <element value="Topic" /> 59 50 </property> 60 51 61 <!-- We do not allow discussion on cinema folders by default -->62 52 <property name="allow_discussion">False</property> 63 53 pleiades.workspace/trunk/pleiades/workspace/tests/base.py
r1327 r1355 48 48 49 49 def afterSetUp(test): 50 lpf = test.portal.portal_types['Workspace Folder'] 50 pt = test.portal.portal_types 51 wf = pt['Workspace Folder'] 52 wf_allow = wf.global_allow 53 wf.global_allow = True 54 55 lpf = pt['Large Plone Folder'] 51 56 lpf_allow = lpf.global_allow 52 57 lpf.global_allow = True 58 59 n = pt['Name'] 60 n_allow = n.global_allow 61 n.global_allow = True 62 63 try: 64 test.setRoles(('Manager', 'Contributor')) 65 test.portal.invokeFactory('Large Plone Folder', id='names') 66 test.portal.invokeFactory('LocationContainer', id='locations') 67 test.portal.invokeFactory('PlaceContainer', id='places') 68 except: 69 raise pleiades.workspace/trunk/pleiades/workspace/tests/factory.txt
r1327 r1355 1 Batch Loading of Entities 2 ========================= 1 Test creation of a workspace 2 ============================ 3 3 4 4 Setup pleiades.workspace/trunk/pleiades/workspace/tests/kml-import.txt
r1294 r1355 61 61 Verify import 62 62 63 >>> 'apollonia-sozousa-portus-cyrenorum' in ws['names']63 >>> 'apollonia-sozousa-portus-cyrenorum' in [o.id for o in ws['names'].queryCatalog()] 64 64 True 65 >>> 'ptolemais-barkes-limen' in ws['names']65 >>> 'ptolemais-barkes-limen' in [o.id for o in ws['names'].queryCatalog()] 66 66 True 67 >>> len( ws['locations'])67 >>> len(list(ws['locations'].queryCatalog())) 68 68 11 pleiades.workspace/trunk/pleiades/workspace/tests/test_doctest.py
r1313 r1355 6 6 from pleiades.workspace.tests import base 7 7 8 optionflags = ( 9 doctest.REPORT_ONLY_FIRST_FAILURE | 10 doctest.NORMALIZE_WHITESPACE | 11 doctest.ELLIPSIS 12 ) 8 13 9 14 def test_suite(): … … 13 18 package='pleiades.workspace.tests', 14 19 test_class=base.WorkspaceFunctionalTestCase, 15 optionflags=doctest.REPORT_ONLY_FIRST_FAILURE | doctest.NORMALIZE_WHITESPACE | doctest.ELLIPSIS), 20 optionflags=optionflags 21 ), 22 ztc.ZopeDocFileSuite( 23 'workspaces.txt', 24 package='pleiades.workspace.tests', 25 test_class=base.WorkspaceFunctionalTestCase, 26 optionflags=optionflags 27 ), 16 28 ztc.ZopeDocFileSuite( 17 29 'kml-import.txt', pleiades.workspace/trunk/pleiades/workspace/tests/xml-import.txt
r1313 r1355 60 60 Verify import 61 61 62 >>> len( ws['locations'])62 >>> len(list(ws['locations'].queryCatalog())) 63 63 264 64 >>> len( ws['places'])64 >>> len(list(ws['places'].queryCatalog())) 65 65 315 66 >>> 'aloanda' in ws['names']66 >>> 'aloanda' in [o.id for o in ws['names'].queryCatalog()] 67 67 True
