Package ZenRelations :: Module PrimaryPathObjectManager
[hide private]
[frames] | no frames]

Source Code for Module ZenRelations.PrimaryPathObjectManager

  1  ########################################################################### 
  2  # 
  3  # This program is part of Zenoss Core, an open source monitoring platform. 
  4  # Copyright (C) 2007, Zenoss Inc. 
  5  # 
  6  # This program is free software; you can redistribute it and/or modify it 
  7  # under the terms of the GNU General Public License version 2 as published by 
  8  # the Free Software Foundation. 
  9  # 
 10  # For complete information please visit: http://www.zenoss.com/oss/ 
 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  # base classes for PrimaryPathObjectManager 
 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   
37 -class PrimaryPathManager(ZItem, Implicit, RoleManager):
38
39 - def getPrimaryPath(self, fromNode=None):
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
60 - def getPrimaryId(self, fromNode=None):
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
67 - def getPrimaryUrlPath(self, full=False):
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
75 - def primaryAq(self):
76 """Return self with is acquisition path set to primary path""" 77 app = self.getPhysicalRoot() 78 return getObjByPath(app, self.getPrimaryPath())
79 80
81 - def getPrimaryParent(self):
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
99 - def _setObject(self, id, obj, roles=None, user=None, set_owner=1):
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
105 - def _delObject(self, id, dp=1):
106 """When deleted clear __primary_parent__.""" 107 obj = self._getOb(id) 108 ObjectManager._delObject(self, id, dp) 109 obj.__primary_parent__ = None
110 111
112 -class PrimaryPathBTreeFolder2(BTreeFolder2):
113 """ 114 BTreeFolder2 PrimaryPathObjectManager. 115 """
116 - def _setObject(self, id, obj, roles=None, user=None, set_owner=1):
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
122 - def _delObject(self, id, dp=1):
123 """When deleted clear __primary_parent__.""" 124 obj = self._getOb(id) 125 ObjectManager._delObject(self, id, dp) 126 obj.__primary_parent__ = None
127