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