[Zope-CVS] CVS: Products/DBTab - Mount.py:1.4 MountedObject.py:1.4
Shane Hathaway
shane@zope.com
Thu, 6 Feb 2003 15:30:19 -0500
Update of /cvs-repository/Products/DBTab
In directory cvs.zope.org:/tmp/cvs-serv29217
Modified Files:
Mount.py MountedObject.py
Log Message:
Changed the strategy for locating mount points. The volatile attribute was
unreliable. Now containers of mount points store the mount point in two ways:
as a folder item (which will automatically resolve itself) and as an item
in the _mount_points dictionary (which will not resolve itself).
=== Products/DBTab/Mount.py 1.3 => 1.4 ===
--- Products/DBTab/Mount.py:1.3 Wed Feb 5 14:45:42 2003
+++ Products/DBTab/Mount.py Thu Feb 6 15:30:18 2003
@@ -95,9 +95,8 @@
raise
try:
- # Make it possible to find the mount point object by poking
- # an attribute into the mounted object.
- # Also, hide from acquisition in a tuple.
+ # XXX This method of finding the mount point is deprecated.
+ # Do not use the _v_mount_point_ attribute.
data._v_mount_point_ = (aq_base(self),)
except:
# Might be a read-only object.
=== Products/DBTab/MountedObject.py 1.3 => 1.4 ===
--- Products/DBTab/MountedObject.py:1.3 Fri Jan 31 18:34:50 2003
+++ Products/DBTab/MountedObject.py Thu Feb 6 15:30:18 2003
@@ -19,6 +19,7 @@
import os
import Globals
+from Acquisition import aq_base, aq_inner, aq_parent
from AccessControl.ZopeGuards import guarded_getattr
from OFS.SimpleItem import SimpleItem
from OFS.Folder import Folder, manage_addFolder
@@ -65,6 +66,9 @@
else:
manage_addFolder(container, part)
o = container.unrestrictedTraverse(part)
+ # Commit a subtransaction to assign the new object to
+ # the correct database.
+ get_transaction().commit(1)
container = o
return container
@@ -149,6 +153,23 @@
Globals.InitializeClass(MountedObject)
+def getMountPoint(ob):
+ container = aq_parent(aq_inner(ob))
+ mps = getattr(container, '_mount_points', None)
+ if mps:
+ return mps.get(ob.getId())
+ return None
+
+
+def setMountPoint(container, id, mp):
+ mps = getattr(container, '_mount_points', None)
+ if mps is None:
+ container._mount_points = {id: aq_base(mp)}
+ else:
+ container._p_changed = 1
+ mps[id] = aq_base(mp)
+
+
manage_addMountsForm = PageTemplateFile('addMountsForm.pt', _www)
def manage_getMountStatus(dispatcher):
@@ -175,13 +196,21 @@
status = o._v_connect_error
else:
exists = 1
- mp = getattr(o, '_v_mount_point_', None)
+ mp = getMountPoint(o)
if mp is None:
- status = '** Something is in the way **'
+ mp_old = getattr(o, '_v_mount_point_', None)
+ if mp_old is not None:
+ # Use the old method of accessing mount points
+ # to update to the new method.
+ # Update the container right now.
+ setMountPoint(dispatcher.this(), o.getId(), mp_old[0])
+ status = 'Ok (updated)'
+ else:
+ status = '** Something is in the way **'
else:
- mp_path = getattr(mp[0], '_path', None)
+ mp_path = getattr(mp, '_path', None)
if mp_path != path:
- status = '** Set to wrong path: %s **' % mp_path
+ status = '** Set to wrong path: %s **' % repr(mp_path)
else:
status = 'Ok'
res.append({
@@ -203,6 +232,7 @@
# Raise an error now if there is any problem.
mo._test(app)
container = traverseOrConstruct(app, path, omit_final=1)
+ mo._p_jar = container._p_jar
loaded = mo.__of__(container)
# Add a faux object to avoid generating manage_afterAdd() events
@@ -214,6 +244,7 @@
container._setObject(faux.id, faux)
del mo._create_mount_points
container._setOb(faux.id, mo)
+ setMountPoint(container, faux.id, mo)
count += 1
if REQUEST is not None:
REQUEST['RESPONSE'].redirect(