Commit 44192455 authored by Jim Fulton's avatar Jim Fulton

Made sub-object access more abstract to work with collections

that don't store sub-objects in attributes.
parent e5f18e26
...@@ -83,7 +83,7 @@ ...@@ -83,7 +83,7 @@
# #
############################################################################## ##############################################################################
__doc__="""Copy interface""" __doc__="""Copy interface"""
__version__='$Revision: 1.30 $'[11:-2] __version__='$Revision: 1.31 $'[11:-2]
import sys, string, Globals, Moniker, tempfile, ExtensionClass import sys, string, Globals, Moniker, tempfile, ExtensionClass
from marshal import loads, dumps from marshal import loads, dumps
...@@ -94,6 +94,7 @@ from App.Dialogs import MessageDialog ...@@ -94,6 +94,7 @@ from App.Dialogs import MessageDialog
CopyError='Copy Error' CopyError='Copy Error'
_marker=[]
class CopyContainer(ExtensionClass.Base): class CopyContainer(ExtensionClass.Base):
"""Interface for containerish objects which allow cut/copy/paste""" """Interface for containerish objects which allow cut/copy/paste"""
...@@ -102,7 +103,21 @@ class CopyContainer(ExtensionClass.Base): ...@@ -102,7 +103,21 @@ class CopyContainer(ExtensionClass.Base):
('manage_cutObjects', 'manage_copyObjects', 'manage_pasteObjects', ('manage_cutObjects', 'manage_copyObjects', 'manage_pasteObjects',
'manage_renameForm', 'manage_renameObject',)), 'manage_renameForm', 'manage_renameObject',)),
) )
# The following three methods should be overridden to store sub-objects
# as non-attributes.
def _setOb(self, id, object): setattr(self, id, object)
def _delOb(self, id): delattr(self, id)
def _getOb(self, id, default=_marker):
if hasattr(self, 'aq_base'): self=self.aq_base
if default is _marker: return getattr(self, id)
try: return getattr(self, id)
except: return default
def manage_CopyContainerFirstItem(self, REQUEST):
return self._getOb(REQUEST['ids'][0])
def manage_cutObjects(self, ids, REQUEST=None): def manage_cutObjects(self, ids, REQUEST=None):
"""Put a reference to the objects named in ids in the clip board""" """Put a reference to the objects named in ids in the clip board"""
...@@ -110,7 +125,7 @@ class CopyContainer(ExtensionClass.Base): ...@@ -110,7 +125,7 @@ class CopyContainer(ExtensionClass.Base):
ids=[ids] ids=[ids]
oblist=[] oblist=[]
for id in ids: for id in ids:
ob=getattr(self, id) ob=self._getOb(id)
if not ob.cb_isMoveable(): if not ob.cb_isMoveable():
raise CopyError, eNotSupported % id raise CopyError, eNotSupported % id
m=Moniker.Moniker(ob) m=Moniker.Moniker(ob)
...@@ -129,7 +144,7 @@ class CopyContainer(ExtensionClass.Base): ...@@ -129,7 +144,7 @@ class CopyContainer(ExtensionClass.Base):
ids=[ids] ids=[ids]
oblist=[] oblist=[]
for id in ids: for id in ids:
ob=getattr(self, id) ob=self._getOb(id)
if not ob.cb_isCopyable(): if not ob.cb_isCopyable():
raise CopyError, eNotSupported % id raise CopyError, eNotSupported % id
m=Moniker.Moniker(ob) m=Moniker.Moniker(ob)
...@@ -224,7 +239,7 @@ class CopyContainer(ExtensionClass.Base): ...@@ -224,7 +239,7 @@ class CopyContainer(ExtensionClass.Base):
title='Invalid Id', title='Invalid Id',
message=sys.exc_value, message=sys.exc_value,
action ='manage_main') action ='manage_main')
ob=getattr(self, id) ob=self._getOb(id)
if not ob.cb_isMoveable(): if not ob.cb_isMoveable():
raise CopyError, eNotSupported % id raise CopyError, eNotSupported % id
self._verifyObjectPaste(ob, REQUEST) self._verifyObjectPaste(ob, REQUEST)
...@@ -317,7 +332,7 @@ class CopyContainer(ExtensionClass.Base): ...@@ -317,7 +332,7 @@ class CopyContainer(ExtensionClass.Base):
meth=None meth=None
if hasattr(self, method_name): if hasattr(self, method_name):
meth=getattr(self, method_name) meth=self._getOb(method_name)
else: else:
# Handle strange names that come from the Product # Handle strange names that come from the Product
# machinery ;( # machinery ;(
......
...@@ -84,9 +84,9 @@ ...@@ -84,9 +84,9 @@
############################################################################## ##############################################################################
__doc__="""Object Manager __doc__="""Object Manager
$Id: ObjectManager.py,v 1.63 1999/04/08 14:04:54 brian Exp $""" $Id: ObjectManager.py,v 1.64 1999/04/09 17:05:23 jim Exp $"""
__version__='$Revision: 1.63 $'[11:-2] __version__='$Revision: 1.64 $'[11:-2]
import App.Management, Acquisition, App.Undo, Globals, CopySupport import App.Management, Acquisition, App.Undo, Globals, CopySupport
import os, App.FactoryDispatcher, ts_regex, Products import os, App.FactoryDispatcher, ts_regex, Products
...@@ -351,10 +351,10 @@ class ObjectManager( ...@@ -351,10 +351,10 @@ class ObjectManager(
r=[] r=[]
if hasattr(self.aq_base,'tree_ids'): if hasattr(self.aq_base,'tree_ids'):
for id in self.aq_base.tree_ids: for id in self.aq_base.tree_ids:
if hasattr(self, id): r.append(getattr(self, id)) if hasattr(self, id): r.append(self._getOb(id))
else: else:
for id in self._objects: for id in self._objects:
o=getattr(self, id['id']) o=self._getOb(id['id'])
try: try:
if o.isPrincipiaFolderish: r.append(o) if o.isPrincipiaFolderish: r.append(o)
except: pass except: pass
...@@ -366,7 +366,7 @@ class ObjectManager( ...@@ -366,7 +366,7 @@ class ObjectManager(
"""Exports a folder and its contents to /var/export.bbe """Exports a folder and its contents to /var/export.bbe
This file can later be imported by using manage_importHack""" This file can later be imported by using manage_importHack"""
if id is None: o=self if id is None: o=self
else: o=getattr(self.o) else: o=self._getOb(id)
f=Globals.data_dir+'/export.bbe' f=Globals.data_dir+'/export.bbe'
o._p_jar.export_file(o,f) o._p_jar.export_file(o,f)
return f return f
...@@ -388,7 +388,7 @@ class ObjectManager( ...@@ -388,7 +388,7 @@ class ObjectManager(
id=self.id id=self.id
if callable(id): id=id() if callable(id): id=id()
ob=self ob=self
else: ob=getattr(self,id) else: ob=self._getOb(id)
if download: if download:
f=StringIO() f=StringIO()
ob._p_jar.export_file(ob, f) ob._p_jar.export_file(ob, f)
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
</HEAD> </HEAD>
<BODY BGCOLOR="#FFFFFF" LINK="#000099" VLINK="#555555"> <BODY BGCOLOR="#FFFFFF" LINK="#000099" VLINK="#555555">
<!--#if expr="_.hasattr(REQUEST, 'ids') and REQUEST['ids']"--> <!--#if expr="_.hasattr(REQUEST, 'ids') and REQUEST['ids']"-->
<!--#with expr="_.getattr(this(), REQUEST['ids'][0])"--> <!--#with expr="manage_CopyContainerFirstItem(REQUEST)"-->
<!--#if cb_isMoveable--> <!--#if cb_isMoveable-->
<H2>Rename <!--#var meta_type--></H2> <H2>Rename <!--#var meta_type--></H2>
<P> <P>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment