Package Products :: Package ZenRelations :: Module ToManyRelationshipBase
[hide private]
[frames] | no frames]

Source Code for Module Products.ZenRelations.ToManyRelationshipBase

  1  ############################################################################## 
  2  #  
  3  # Copyright (C) Zenoss, Inc. 2007, all rights reserved. 
  4  #  
  5  # This content is made available according to terms specified in 
  6  # License.zenoss under the directory where your Zenoss product is installed. 
  7  #  
  8  ############################################################################## 
  9   
 10   
 11  __doc__ = """ToManyRelationshipBase 
 12  Base class for 1:n relations 
 13  """ 
 14  import logging 
 15  log = logging.getLogger('zen.ToManyRelationshipBase') 
 16   
 17  # Base classes for ToManyRelationshipBase 
 18  #from PrimaryPathObjectManager import PrimaryPathObjectManager 
 19  from RelationshipBase import RelationshipBase 
 20  from RelCopySupport import RelCopyContainer 
 21   
 22  from Globals import DTMLFile 
 23  from AccessControl import ClassSecurityInfo 
 24  from Globals import InitializeClass 
 25  from App.Management import Tabs 
 26   
 27  from Products.ZenRelations.Exceptions import zenmarker 
 28  from Products.ZenUtils.Utils import unused 
 29   
30 -class ToManyRelationshipBase( 31 RelCopyContainer, 32 RelationshipBase 33 ):
34 """ 35 Abstract base class for all ToMany relationships. 36 """ 37 38 manage_options = ( 39 { 40 'action': 'manage_main', 41 'help': ('OFSP', 'ObjectManager_Contents.stx'), 42 'label': 'Contents'}, 43 ) 44 45 security = ClassSecurityInfo() 46 47 manage_main = DTMLFile('dtml/ToManyRelationshipMain',globals()) 48 49 _operation = -1 # if a Relationship's are only deleted 50 51 _count = None 52
53 - def setCount(self):
54 self._count = len(self._objects) 55 # persist the changes if we are on the object graph 56 try: 57 parent = self.__primary_parent__ 58 parent._p_changed = True 59 except AttributeError: 60 log.debug("Unable to persist the count of %s" % self.id)
61
62 - def countObjects(self):
63 """Return the number of objects in this relationship""" 64 if self._count is None: 65 self.setCount() 66 return self._count
67 68
69 - def findObjectsById(self, partid):
70 """Return a list of objects by running find on their id""" 71 objects = [] 72 for id, obj in self.objectItemsAll(): 73 if id.find(partid) > -1: 74 objects.append(obj) 75 return objects
76 77
78 - def _delObject(self, id, dp=1, suppress_events=False):
79 """Emulate ObjectManager deletetion.""" 80 unused(dp) 81 obj = self._getOb(id, False) 82 if not obj: 83 log.warning( 84 "Tried to delete object id '%s' but didn't find it on %s", 85 id, self.getPrimaryId()) 86 return 87 self.removeRelation(obj, suppress_events) 88 obj.__primary_parent__ = None
89 90
91 - def _setOb(self, id, obj):
92 """don't use attributes in relations""" 93 unused(id) 94 unused(obj) 95 if True: 96 raise NotImplementedError
97 98
99 - def _delOb(self, id):
100 """don't use attributes in relations""" 101 if True: 102 raise NotImplementedError
103 104
105 - def _getOb(self, id, default=zenmarker):
106 """ 107 Return object by id if it exists on this relationship. 108 If it doesn't exist return default or if default is not set 109 raise AttributeError 110 """ 111 unused(default) 112 if True: 113 raise NotImplementedError
114 115
116 - def manage_workspace(self, REQUEST):
117 """if this has been called on us return our workspace 118 if not redirect to the workspace of a related object""" 119 id = REQUEST['URL'].split('/')[-2] 120 if id == self.id: 121 Tabs.manage_workspace(self, REQUEST) 122 else: 123 obj = self._getOb(self, id) 124 from zExceptions import Redirect 125 raise Redirect( (obj.getPrimaryUrlPath()+'/manage_workspace') )
126 127 128 InitializeClass(ToManyRelationshipBase) 129