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 import logging
21 log = logging.getLogger("zen.PrimaryPathObjectManager")
22
23
24 from RelCopySupport import RelCopyContainer
25 from Acquisition import Implicit, aq_base
26 from OFS.ObjectManager import ObjectManager
27 from AccessControl.Role import RoleManager
28 import App.Undo
29
30 from ZItem import ZItem
31
32
33 from Products.ZenUtils.Utils import getObjByPath
34
35 from Products.BTreeFolder2.BTreeFolder2 import BTreeFolder2
36
37
38
40
42 """
43 Return the primary path of this object by following __primary_parent__
44 """
45 ppath = []
46 obj = aq_base(self)
47 while True:
48 ppath.append(obj.id)
49 parent = getattr(obj, "__primary_parent__", None)
50 if parent is None: break
51 obj = parent
52 ppath.reverse()
53 basepath = getattr(obj, "zPrimaryBasePath", [])
54 for i in range(len(basepath)-1,-1,-1): ppath.insert(0,basepath[i])
55 try:
56 idx = ppath.index(fromNode)
57 ppath = ppath[idx+1:]
58 except ValueError: pass
59 return tuple(ppath)
60
61
63 """Return the primary path in the form /zport/dmd/xyz"""
64 pid = "/".join(self.getPrimaryPath(fromNode))
65 if fromNode: pid = "/" + pid
66 return pid
67
68
70 """Return the primary path as an absolute url"""
71 objaq = self.primaryAq()
72 if full: return objaq.absolute_url()
73 return objaq.absolute_url_path()
74
75
76
78 """Return self with is acquisition path set to primary path"""
79 app = self.getPhysicalRoot()
80 return getObjByPath(app, self.getPrimaryPath())
81
82
84 """Return our parent object by our primary path"""
85 return self.__primary_parent__.primaryAq()
86
87
88 -class PrimaryPathObjectManager(
89 RelCopyContainer,
90 ObjectManager,
91 PrimaryPathManager,
92 App.Undo.UndoSupport,
93 ):
94 """
95 PrimaryPathObjectManager with basic Zope persistent classes.
96 """
97 manage_options = (ObjectManager.manage_options +
98 RoleManager.manage_options +
99 ZItem.manage_options)
100
101 - def _setObject(self, id, obj, roles=None, user=None, set_owner=1):
102 """Track __primary_parent__ when we are set into an object"""
103 obj.__primary_parent__ = aq_base(self)
104 return ObjectManager._setObject(self, id, obj, roles, user, set_owner)
105
106
108 """When deleted clear __primary_parent__."""
109 obj = self._getOb(id, None)
110 if obj is None:
111
112
113
114
115
116
117
118 log.warning(
119 "Tried to delete object id '%s' but didn't find it on %s",
120 id, self.getPrimaryId())
121 return
122 ObjectManager._delObject(self, id, dp)
123 obj.__primary_parent__ = None
124
125
127 """
128 BTreeFolder2 PrimaryPathObjectManager.
129 """
130 - def _setObject(self, id, obj, roles=None, user=None, set_owner=1):
131 """Track __primary_parent__ when we are set into an object"""
132 obj.__primary_parent__ = aq_base(self)
133 return ObjectManager._setObject(self, id, obj, roles, user, set_owner)
134
135
137 """When deleted clear __primary_parent__."""
138 obj = self._getOb(id)
139 ObjectManager._delObject(self, id, dp)
140 obj.__primary_parent__ = None
141