1
2
3
4
5
6
7
8
9
10
11
12
13
14 __doc__="""PrimaryPathObjectManager
15
16 $Id: RelationshipBase.py,v 1.26 2003/10/03 16:16:01 edahl Exp $"""
17
18 __version__ = "$Revision: 1.26 $"[11:-2]
19
20
21 from RelCopySupport import RelCopyContainer
22 from OFS.Traversable import Traversable
23 from Acquisition import Implicit, aq_base
24 from OFS.ObjectManager import ObjectManager
25 from AccessControl.Role import RoleManager
26 import App.Undo
27
28 from ZItem import ZItem
29
30
31 from Products.ZenUtils.Utils import getObjByPath
32
33 from Products.BTreeFolder2.BTreeFolder2 import BTreeFolder2
34
35
36
38
40 """
41 Return the primary path of this object by following __primary_parent__
42 """
43 ppath = []
44 obj = aq_base(self)
45 while True:
46 ppath.append(obj.id)
47 parent = getattr(obj, "__primary_parent__", None)
48 if parent is None: break
49 obj = parent
50 ppath.reverse()
51 basepath = getattr(obj, "zPrimaryBasePath", [])
52 for i in range(len(basepath)-1,-1,-1): ppath.insert(0,basepath[i])
53 try:
54 idx = ppath.index(fromNode)
55 ppath = ppath[idx+1:]
56 except ValueError: pass
57 return tuple(ppath)
58
59
61 """Return the primary path in the form /zport/dmd/xyz"""
62 pid = "/".join(self.getPrimaryPath(fromNode))
63 if fromNode: pid = "/" + pid
64 return pid
65
66
68 """Return the primary path as an absolute url"""
69 objaq = self.primaryAq()
70 if full: return objaq.absolute_url()
71 return objaq.absolute_url_path()
72
73
74
76 """Return self with is acquisition path set to primary path"""
77 app = self.getPhysicalRoot()
78 return getObjByPath(app, self.getPrimaryPath())
79
80
82 """Return our parent object by our primary path"""
83 return self.__primary_parent__.primaryAq()
84
85
86 -class PrimaryPathObjectManager(
87 RelCopyContainer,
88 ObjectManager,
89 PrimaryPathManager,
90 App.Undo.UndoSupport,
91 ):
92 """
93 PrimaryPathObjectManager with basic Zope persistent classes.
94 """
95 manage_options = (ObjectManager.manage_options +
96 RoleManager.manage_options +
97 ZItem.manage_options)
98
100 """Track __primary_parent__ when we are set into an object"""
101 obj.__primary_parent__ = aq_base(self)
102 return ObjectManager._setObject(self, id, obj, roles, user, set_owner)
103
104
106 """When deleted clear __primary_parent__."""
107 obj = self._getOb(id)
108 ObjectManager._delObject(self, id, dp)
109 obj.__primary_parent__ = None
110
111
113 """
114 BTreeFolder2 PrimaryPathObjectManager.
115 """
117 """Track __primary_parent__ when we are set into an object"""
118 obj.__primary_parent__ = aq_base(self)
119 return ObjectManager._setObject(self, id, obj, roles, user, set_owner)
120
121
123 """When deleted clear __primary_parent__."""
124 obj = self._getOb(id)
125 ObjectManager._delObject(self, id, dp)
126 obj.__primary_parent__ = None
127