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__="""$Id: ToManyRelationship.py,v 1.48 2003/11/12 22:05:48 edahl Exp $""" 
 16   
 17  __version__ = "$Revision: 1.48 $"[11:-2] 
 18   
 19  # Base classes for ToManyRelationshipBase 
 20  #from PrimaryPathObjectManager import PrimaryPathObjectManager 
 21  from RelationshipBase import RelationshipBase 
 22  from RelCopySupport import RelCopyContainer 
 23  from OFS.Traversable import Traversable 
 24  from Acquisition import Implicit 
 25   
 26  from Globals import DTMLFile 
 27  from Acquisition import aq_base, aq_parent 
 28  from AccessControl import ClassSecurityInfo 
 29  from Globals import InitializeClass 
 30  from App.Management import Tabs 
 31   
 32  from Products.ZenRelations.Exceptions import zenmarker 
 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 obj = self._getOb(id) 73 self.removeRelation(obj) 74 obj.__primary_parent__ = None
75 76
77 - def _setOb(self, id, obj):
78 """don't use attributes in relations""" 79 raise NotImplementedError
80 81
82 - def _delOb(self, id):
83 """don't use attributes in relations""" 84 raise NotImplementedError
85 86
87 - def _getOb(self, id, default=zenmarker):
88 """ 89 Return object by id if it exists on this relationship. 90 If it doesn't exist return default or if default is not set 91 raise AttributeError 92 """ 93 raise NotImplementedError
94 95
96 - def manage_workspace(self, REQUEST):
97 """if this has been called on us return our workspace 98 if not redirect to the workspace of a related object""" 99 id = REQUEST['URL'].split('/')[-2] 100 if id == self.id: 101 Tabs.manage_workspace(self, REQUEST) 102 else: 103 obj = self._getOb(self, id) 104 raise "Redirect", (obj.getPrimaryUrlPath()+'/manage_workspace')
105 106 107 InitializeClass(ToManyRelationshipBase) 108