Changeset 1355

Show
Ignore:
Timestamp:
08/08/08 00:48:52 (4 months ago)
Author:
sgillies
Message:

Get KML and XML imports working with new smart foldering

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • pleiades.workspace/trunk/pleiades/workspace/browser/kml.py

    r1294 r1355  
    66from elementtree import ElementTree as etree 
    77import keytree 
     8from pleiades.workspace.interfaces import IResource 
     9 
    810 
    911class KMLImporter(BrowserView): 
     
    1517        request = self.request 
    1618        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() 
    2220        ptool = getToolByName(self.context, 'plone_utils') 
    2321 
     22        places = portal['places'] 
     23        names = portal['names'] 
     24        locations = portal['locations'] 
     25         
    2426        savepoint = transaction.savepoint() 
    25  
    2627        try: 
    2728            k = etree.fromstring(request.file.read()) 
     
    5556                a.addReference(names[nid], 'hasName') 
    5657                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                 
    5764        except: 
    5865            savepoint.rollback() 
  • pleiades.workspace/trunk/pleiades/workspace/browser/xml.py

    r1313 r1355  
    1 #from Acquisition import aq_inner 
     1import glob 
     2from os.path import basename 
     3from elementtree import ElementTree as etree 
    24import transaction 
    35from Products.Five.browser import BrowserView 
    46from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile 
    57from Products.CMFCore.utils import getToolByName 
    6 from elementtree import ElementTree as etree 
    78import keytree 
    8 from Products.PleiadesEntity.Extensions.loader import loaden 
     9from Products.PleiadesEntity.Extensions.loader import load_place 
     10from pleiades.workspace.interfaces import IResource 
    911 
    1012 
     
    1618    def __call__(self): 
    1719        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 
    1946 
    2047 
  • pleiades.workspace/trunk/pleiades/workspace/configure.zcml

    r1287 r1355  
    1111  <include package=".content" /> 
    1212 
     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 
    1343  <genericsetup:registerProfile 
    1444    name="default" 
  • pleiades.workspace/trunk/pleiades/workspace/content/workspace.py

    r1288 r1355  
    1 """Definition of the CinemaFolder content type and associated schemata and 
    2 other logic. 
    3  
    4 This file contains a number of comments explaining the various lines of 
    5 code. Other files in this sub-package contain analogous code, but will  
    6 not be commented as heavily. 
    7  
    8 Please see README.txt for more information on how the content types in 
    9 this package are used. 
    10 """ 
    11  
    121from zope.interface import implements 
    132from zope.component import adapter, getMultiAdapter, getUtility 
     
    9483    text = atapi.ATFieldProperty('text') 
    9584 
     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 
    9692    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') 
    10099 
    101100# This line tells Archetypes about the content type 
  • pleiades.workspace/trunk/pleiades/workspace/interfaces.py

    r1327 r1355  
    1 from zope.interface import Interface 
     1from zope.interface import Interface, Attribute 
    22from zope import schema 
    33 
     
    55 
    66from pleiades.workspace import WorkspaceMessageFactory as _ 
     7 
     8 
     9class 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 
    719 
    820class IWorkspace(Interface): 
  • pleiades.workspace/trunk/pleiades/workspace/profiles/default/types/Workspace.xml

    r1288 r1355  
    4141  <property name="immediate_view">atct_edit</property> 
    4242  
    43  <!-- global_allow specifies whether the object is generally addable. If 
    44       this is False, only those folders that set filter_content_types to 
    45       True and includes the portal_type of this object in the list of 
    46       allowed_content_types will allow creation of this type. Here, 
    47       we let cinema folders be addable in normal folders (provided the 
    48       user has the appropriate permissions, of course). We then explicitly 
    49       filter the content types allowed inside a Cinema Folder, restricting 
    50       them to Cinema, Promotion and other nested Cinema Folders. Of course,  
    51       this can be changed in the ZODB later. 
    52    --> 
    5343  <property name="global_allow">True</property> 
    5444  <property name="filter_content_types">True</property> 
     
    5747    <element value="Location Container" /> 
    5848    <element value="Folder" /> 
     49    <element value="Topic" /> 
    5950  </property> 
    6051  
    61  <!-- We do not allow discussion on cinema folders by default --> 
    6252  <property name="allow_discussion">False</property> 
    6353  
  • pleiades.workspace/trunk/pleiades/workspace/tests/base.py

    r1327 r1355  
    4848 
    4949    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'] 
    5156        lpf_allow = lpf.global_allow 
    5257        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 ========================= 
     1Test creation of a workspace 
     2============================ 
    33 
    44Setup 
  • pleiades.workspace/trunk/pleiades/workspace/tests/kml-import.txt

    r1294 r1355  
    6161Verify import 
    6262 
    63     >>> 'apollonia-sozousa-portus-cyrenorum' in ws['names'
     63    >>> 'apollonia-sozousa-portus-cyrenorum' in [o.id for o in ws['names'].queryCatalog()
    6464    True 
    65     >>> 'ptolemais-barkes-limen' in ws['names'
     65    >>> 'ptolemais-barkes-limen' in [o.id for o in ws['names'].queryCatalog()
    6666    True 
    67     >>> len(ws['locations']
     67    >>> len(list(ws['locations'].queryCatalog())
    6868    11 
  • pleiades.workspace/trunk/pleiades/workspace/tests/test_doctest.py

    r1313 r1355  
    66from pleiades.workspace.tests import base 
    77 
     8optionflags = ( 
     9    doctest.REPORT_ONLY_FIRST_FAILURE |  
     10    doctest.NORMALIZE_WHITESPACE |  
     11    doctest.ELLIPSIS 
     12    ) 
    813 
    914def test_suite(): 
     
    1318            package='pleiades.workspace.tests', 
    1419            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            ), 
    1628        ztc.ZopeDocFileSuite( 
    1729            'kml-import.txt', 
  • pleiades.workspace/trunk/pleiades/workspace/tests/xml-import.txt

    r1313 r1355  
    6060Verify import 
    6161 
    62     >>> len(ws['locations']
     62    >>> len(list(ws['locations'].queryCatalog())
    6363    264 
    64     >>> len(ws['places']
     64    >>> len(list(ws['places'].queryCatalog())
    6565    315 
    66     >>> 'aloanda' in ws['names'
     66    >>> 'aloanda' in [o.id for o in ws['names'].queryCatalog()
    6767    True