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

Source Code for Module Products.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 or (at your 
  8  # option) any later version as published by 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 zope.interface import implements 
 27   
 28  from Products.ZenModel.interfaces import IIndexed 
 29  from Products.ZenModel.ZenossSecurity import * 
 30  from Products.ZenWidgets import messaging 
 31   
 32  from ZenModelRM import ZenModelRM 
 33  from ZenPackable import ZenPackable 
 34   
 35  from Products.ZenRelations.RelSchema import * 
 36   
37 -class ProductClass(ZenModelRM, ZenPackable):
38 implements(IIndexed) 39 meta_type = "ProductClass" 40 41 #itclass = "" 42 name = "" 43 productKeys = [] 44 isOS = False 45 46 default_catalog = "productSearch" 47 48 _properties = ( 49 #{'id':'itclass', 'type':'string', 'mode':'w'}, 50 {'id':'name', 'type':'string', 'mode':'w'}, 51 {'id':'productKeys', 'type':'lines', 'mode':'w'}, 52 {'id':'partNumber', 'type':'string', 'mode':'w'}, 53 {'id':'description', 'type':'string', 'mode':'w'}, 54 {'id':'isOS', 'type':'boolean', 'mode':'w'}, 55 ) 56 57 _relations = ZenPackable._relations + ( 58 ("instances", ToMany(ToOne, "Products.ZenModel.MEProduct", "productClass")), 59 ("manufacturer", ToOne(ToManyCont,"Products.ZenModel.Manufacturer","products")), 60 ) 61 62 factory_type_information = ( 63 { 64 'id' : 'ProductClass', 65 'meta_type' : 'ProductClass', 66 'description' : """Class to manage product information""", 67 'icon' : 'ProductClass.gif', 68 'product' : 'ZenModel', 69 'factory' : 'manage_addProductClass', 70 'immediate_view' : 'viewProductClassOverview', 71 'actions' : 72 ( 73 { 'id' : 'overview' 74 , 'name' : 'Overview' 75 , 'action' : 'viewProductClassOverview' 76 , 'permissions' : ( 77 permissions.view, ) 78 }, 79 { 'id' : 'edit' 80 , 'name' : 'Edit' 81 , 'action' : 'editProductClass' 82 , 'permissions' : ("Manage DMD", ) 83 }, 84 { 'id' : 'config' 85 , 'name' : 'Configuration Properties' 86 , 'action' : 'zPropertyEditNew' 87 , 'permissions' : ("Manage DMD",) 88 }, 89 ) 90 }, 91 ) 92 93 security = ClassSecurityInfo() 94 95
96 - def __init__(self, id, title="", prodName=None, 97 productKey=None, partNumber="",description=""):
98 ZenModelRM.__init__(self, id, title) 99 # XXX per a comment in #406 from Erik, we may want to get rid 100 # of prodName and only use productKey, to avoid redundancy 101 if productKey: 102 self.productKeys = [productKey] 103 elif prodName: 104 self.productKeys = [prodName] 105 else: 106 # When adding manually through the gui both prodName and 107 # productKey will be None 108 self.productKeys = [] 109 if prodName is None: self.name = id 110 else: self.name = prodName 111 self.partNumber = partNumber 112 self.description = description
113 114
115 - def type(self):
116 """Return the type name of this product (Hardware, Software). 117 """ 118 return self.meta_type[:-5]
119 120
121 - def count(self):
122 """Return the number of existing instances for this class. 123 """ 124 return self.instances.countObjects()
125 126
127 - def getProductKey(self):
128 """Return the first product key of the device. 129 """ 130 if len(self.productKeys) > 0: 131 return self.productKeys[0] 132 return ""
133 134
135 - def getManufacturerName(self):
136 if not self.manufacturer(): 137 return '' 138 return self.manufacturer().getId()
139 140 141 security.declareProtected('Manage DMD', 'manage_editProductClass')
142 - def manage_editProductClass(self, name="", productKeys=(), isOS=False, 143 partNumber="", description="", REQUEST=None):
144 """ 145 Edit a ProductClass from a web page. 146 """ 147 redirect = self.rename(name) 148 productKeys = [ l.strip() for l in productKeys.split('\n') ] 149 if productKeys != self.productKeys: 150 self.unindex_object() 151 self.productKeys = productKeys 152 self.index_object() 153 self.partNumber = partNumber 154 self.description = description 155 self.isOS = isOS 156 self.name = name 157 if REQUEST: 158 from Products.ZenUtils.Time import SaveMessage 159 messaging.IMessageSender(self).sendToBrowser( 160 'Product Class Saved', 161 SaveMessage() 162 ) 163 return self.callZenScreen(REQUEST, redirect)
164 165 166 InitializeClass(ProductClass) 167