1
2
3
4
5
6
7
8
9
10
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
22
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
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
54
55 _count = None
56
58 self._count = len(self._objects)
59
60 try:
61 parent = self.__primary_parent__
62 parent._p_changed = True
63 except AttributeError:
64 log.debug("Unable to persist the count of %s" % self.id)
65
67 """Return the number of objects in this relationship"""
68 if self._count is None:
69 self.setCount()
70 return self._count
71
72
80
81
82 - def _delObject(self, id, dp=1, suppress_events=False):
83 """Emulate ObjectManager deletetion."""
84 unused(dp)
85 obj = self._getOb(id, False)
86 if not obj:
87 log.warning(
88 "Tried to delete object id '%s' but didn't find it on %s",
89 id, self.getPrimaryId())
90 return
91 self.removeRelation(obj, suppress_events)
92 obj.__primary_parent__ = None
93
94
96 """don't use attributes in relations"""
97 unused(id)
98 unused(obj)
99 if True:
100 raise NotImplementedError
101
102
104 """don't use attributes in relations"""
105 if True:
106 raise NotImplementedError
107
108
110 """
111 Return object by id if it exists on this relationship.
112 If it doesn't exist return default or if default is not set
113 raise AttributeError
114 """
115 unused(default)
116 if True:
117 raise NotImplementedError
118
119
121 """if this has been called on us return our workspace
122 if not redirect to the workspace of a related object"""
123 id = REQUEST['URL'].split('/')[-2]
124 if id == self.id:
125 Tabs.manage_workspace(self, REQUEST)
126 else:
127 obj = self._getOb(self, id)
128 from zExceptions import Redirect
129 raise Redirect( (obj.getPrimaryUrlPath()+'/manage_workspace') )
130
131
132 InitializeClass(ToManyRelationshipBase)
133