1
2
3
4
5
6
7
8
9
10
11 __doc__="""Collection
12 Holds an assortment of devices and/or components on a multi-style report.
13 """
14 import sys
15
16 from Globals import InitializeClass
17 from AccessControl import ClassSecurityInfo, Permissions
18 from Globals import DTMLFile
19 from Products.ZenRelations.RelSchema import *
20 from ZenModelRM import ZenModelRM
21 from Products.ZenUtils.Utils import resequence
22 from Products.ZenWidgets import messaging
23 from Products.ZenUtils.deprecated import deprecated
24 from Products.ZenMessaging.audit import audit
35
36 addCollection = DTMLFile('dtml/addCollection',globals())
40 """
41 Holds an assortment of devices and/or components on a multi-style report.
42 """
43
44 meta_type = 'Collection'
45
46 _properties = (
47 )
48
49 _relations = (
50 ('report',
51 ToOne(ToManyCont, 'Products.ZenModel.MultiGraphReport', 'collections')),
52 ('collection_items',
53 ToManyCont(ToOne, 'Products.ZenModel.CollectionItem', 'collection')),
54 )
55
56 factory_type_information = (
57 {
58 'immediate_view' : 'editCollection',
59 'actions' :
60 (
61 { 'id' : 'edit'
62 , 'name' : 'Collection'
63 , 'action' : 'editCollection'
64 , 'permissions' : ( Permissions.view, )
65 },
66 )
67 },
68 )
69
70 security = ClassSecurityInfo()
71
72
73 - def createCollectionItem(self, orgPath='', devId='', compPath='',
74 recurse=False, checkExists=False):
95
96
97 security.declareProtected('Manage DMD', 'manage_addCollectionItem')
98 - def manage_addCollectionItem(self, itemType,
99 deviceIds=(), componentPaths=(), deviceClasses=(), systems=(),
100 groups=(), locations=(), recurse=False, REQUEST=None):
101 ''' Create a new CollectionItem and add to this collection
102 '''
103 count = 0
104 if itemType == 'devcomp':
105 if not deviceIds:
106 deviceIds = []
107 if not componentPaths:
108 componentPaths = ['']
109 for i, devId in enumerate(deviceIds):
110 for cPath in componentPaths:
111 ci = self.createCollectionItem(devId=devId, compPath=cPath,
112 recurse=False, checkExists=True)
113 if ci:
114 count += 1
115 if itemType == 'deviceClass':
116 for dClass in deviceClasses:
117 self.createCollectionItem(
118 orgPath='/Devices' + dClass, recurse=recurse)
119 count += 1
120 if itemType == 'system':
121 for system in systems:
122 self.createCollectionItem(
123 orgPath='/Systems' + system, recurse=recurse)
124 count += 1
125 if itemType == 'group':
126 for group in groups:
127 self.createCollectionItem(
128 orgPath='/Groups' + group, recurse=recurse)
129 count += 1
130 if itemType == 'location':
131 for loc in locations:
132 self.createCollectionItem(
133 orgPath='/Locations' + loc, recurse=recurse)
134 count += 1
135
136 if REQUEST:
137 audit('UI.Collection.AddItem', self.id, itemType=itemType, deviceIds=deviceIds,
138 componentPaths=componentPaths, deviceClasses=deviceClasses, systems=systems,
139 groups=groups, locations=locations)
140 messaging.IMessageSender(self).sendToBrowser(
141 'Items Added',
142 ' %s item%s added' % (count, count > 1 and 's' or '')
143 )
144 return self.callZenScreen(REQUEST)
145
146
147 security.declareProtected('Manage DMD', 'manage_deleteCollectionItems')
166
167
168 security.declareProtected('Manage DMD', 'manage_resequenceCollectionItems')
171 """Reorder the sequence of the items.
172 """
173 retval = resequence(self, self.collection_items(), seqmap, origseq, REQUEST)
174 if REQUEST:
175 audit('UI.Collection.ResequenceItems', self.id, sequence=seqmap,
176 oldData_={'sequence':origseq})
177 return retval
178
179
180 security.declareProtected('Manage DMD', 'getItems')
182 ''' Return an ordered list of CollectionItems
183 '''
184 def itemKey(a):
185 try:
186 return int(a.sequence)
187 except ValueError:
188 return sys.maxint
189 return sorted(self.collection_items(), key=itemKey)
190
191
193 ''' Return the number of collection items
194 '''
195 return len(self.collection_items())
196
197
199 ''' Return a deduped list of devices and components represented
200 by this collection's collectionitems
201 '''
202 things = []
203 tset = set()
204 for collectionItem in self.getItems():
205 devsAndComps = collectionItem.getDevicesAndComponents()
206 for devOrComp in devsAndComps:
207 tid = devOrComp.getPrimaryId()
208 if tid not in tset:
209 tset.add(tid)
210 things.append(devOrComp)
211 return things
212
213 InitializeClass(Collection)
214