Package ZenModel :: Module ProductClass
[hide private]
[frames] | no frames]

Source Code for Module ZenModel.ProductClass

  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  __doc__="""ProductClass 
 15   
 16  The product classification class.  default identifiers, screens, 
 17  and data collectors live here. 
 18   
 19  $Id: ProductClass.py,v 1.10 2004/03/26 23:58:44 edahl Exp $""" 
 20   
 21  __version__ = "$Revision: 1.10 $"[11:-2] 
 22   
 23  from Globals import InitializeClass 
 24  from AccessControl import ClassSecurityInfo 
 25  from AccessControl import Permissions as permissions 
 26  from Products.ZenModel.ZenossSecurity import * 
 27  from Products.ZenWidgets import messaging 
 28   
 29  from ZenModelRM import ZenModelRM 
 30  from ZenPackable import ZenPackable 
 31   
 32  from Products.ZenRelations.RelSchema import * 
 33   
34 -class ProductClass(ZenModelRM, ZenPackable):
35 36 37 meta_type = "ProductClass" 38 39 #itclass = "" 40 name = "" 41 productKeys = [] 42 isOS = False 43 44 default_catalog = "productSearch" 45 46 _properties = ( 47 #{'id':'itclass', 'type':'string', 'mode':'w'}, 48 {'id':'name', 'type':'string', 'mode':'w'}, 49 {'id':'productKeys', 'type':'lines', 'mode':'w'}, 50 {'id':'partNumber', 'type':'string', 'mode':'w'}, 51 {'id':'description', 'type':'string', 'mode':'w'}, 52 {'id':'isOS', 'type':'boolean', 'mode':'w'}, 53 ) 54 55 _relations = ZenPackable._relations + ( 56 ("instances", ToMany(ToOne, "Products.ZenModel.MEProduct", "productClass")), 57 ("manufacturer", ToOne(ToManyCont,"Products.ZenModel.Manufacturer","products")), 58 ) 59 60 factory_type_information = ( 61 { 62 'id' : 'ProductClass', 63 'meta_type' : 'ProductClass', 64 'description' : """Class to manage product information""", 65 'icon' : 'ProductClass.gif', 66 'product' : 'ZenModel', 67 'factory' : 'manage_addProductClass', 68 'immediate_view' : 'viewProductClassOverview', 69 'actions' : 70 ( 71 { 'id' : 'overview' 72 , 'name' : 'Overview' 73 , 'action' : 'viewProductClassOverview' 74 , 'permissions' : ( 75 permissions.view, ) 76 }, 77 { 'id' : 'edit' 78 , 'name' : 'Edit' 79 , 'action' : 'editProductClass' 80 , 'permissions' : ("Manage DMD", ) 81 }, 82 { 'id' : 'config' 83 , 'name' : 'zProperties' 84 , 'action' : 'zPropertyEdit' 85 , 'permissions' : ("Manage DMD",) 86 }, 87 { 'id' : 'viewHistory' 88 , 'name' : 'Modifications' 89 , 'action' : 'viewHistory' 90 , 'permissions' : (ZEN_VIEW_MODIFICATIONS,) 91 }, 92 ) 93 }, 94 ) 95 96 security = ClassSecurityInfo() 97 98
99 - def __init__(self, id, title="", prodName=None, 100 productKey=None, partNumber="",description=""):
101 ZenModelRM.__init__(self, id, title) 102 # XXX per a comment in #406 from Erik, we may want to get rid 103 # of prodName and only use productKey, to avoid redundancy 104 if productKey: 105 self.productKeys = [productKey] 106 elif prodName: 107 self.productKeys = [prodName] 108 else: 109 # When adding manually through the gui both prodName and 110 # productKey will be None 111 self.productKeys = [] 112 if prodName is None: self.name = id 113 else: self.name = prodName 114 self.partNumber = partNumber 115 self.description = description
116 117
118 - def type(self):
119 """Return the type name of this product (Hardware, Software). 120 """ 121 return self.meta_type[:-5]
122 123
124 - def count(self):
125 """Return the number of existing instances for this class. 126 """ 127 return self.instances.countObjects()
128 129
130 - def getProductKey(self):
131 """Return the first product key of the device. 132 """ 133 if len(self.productKeys) > 0: 134 return self.productKeys[0] 135 return ""
136 137
138 - def getManufacturerName(self):
139 if not self.manufacturer(): 140 return '' 141 return self.manufacturer().getId()
142 143
144 - def manage_afterAdd(self, item, container):
145 """ 146 Device only propagates afterAdd if it is the added object. 147 """ 148 super(ProductClass,self).manage_afterAdd(item, container) 149 self.index_object()
150 151
152 - def manage_afterClone(self, item):
153 """Not really sure when this is called.""" 154 super(ProductClass,self).manage_afterClone(item) 155 self.index_object()
156 157
158 - def manage_beforeDelete(self, item, container):
159 """ 160 Device only propagates beforeDelete if we are being deleted or copied. 161 Moving and renaming don't propagate. 162 """ 163 super(ProductClass,self).manage_beforeDelete(item, container) 164 self.unindex_object()
165 166 167 security.declareProtected('Manage DMD', 'manage_editProductClass')
168 - def manage_editProductClass(self, name="", productKeys=(), isOS=False, 169 partNumber="", description="", REQUEST=None):
170 """ 171 Edit a ProductClass from a web page. 172 """ 173 redirect = self.rename(name) 174 productKeys = [ l.strip() for l in productKeys.split('\n') ] 175 if productKeys != self.productKeys: 176 self.unindex_object() 177 self.productKeys = productKeys 178 self.index_object() 179 self.partNumber = partNumber 180 self.description = description 181 self.isOS = isOS 182 self.name = name 183 if REQUEST: 184 from Products.ZenUtils.Time import SaveMessage 185 messaging.IMessageSender(self).sendToBrowser( 186 'Product Class Saved', 187 SaveMessage() 188 ) 189 return self.callZenScreen(REQUEST, redirect)
190 191 192 InitializeClass(ProductClass) 193