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

Source Code for Module ZenRelations.ToManyRelationshipBase

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