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

Source Code for Module Products.ZenModel.Manufacturer

  1  ########################################################################### 
  2  # 
  3  # This program is part of Zenoss Core, an open source monitoring platform. 
  4  # Copyright (C) 2007, 2009 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__="""Manufacturer 
 15   
 16  Manufacturer is a base class that represents a vendor of Products. 
 17   
 18  $Id: Manufacturer.py,v 1.11 2004/03/26 23:58:44 edahl Exp $""" 
 19   
 20  __version__ = "$Revision: 1.11 $"[11:-2] 
 21   
 22  import re 
 23   
 24  from Globals import DTMLFile, InitializeClass 
 25  from AccessControl import ClassSecurityInfo 
 26  from AccessControl import Permissions as permissions 
 27  from Products.ZenModel.ZenossSecurity import * 
 28  from Products.ZenWidgets import messaging 
 29   
 30  from Products.ZenRelations.RelSchema import * 
 31   
 32  from ZenModelRM import ZenModelRM 
 33  from ZenPackable import ZenPackable 
 34   
 35   
36 -def manage_addManufacturer(context, id=None, REQUEST = None):
37 """make a Manufacturer""" 38 if id: 39 d = Manufacturer(id) 40 context._setObject(id, d) 41 42 if REQUEST is not None: 43 REQUEST['RESPONSE'].redirect(context.absolute_url() 44 +'/manage_main')
45 46 addManufacturer = DTMLFile('dtml/addManufacturer',globals()) 47
48 -class Manufacturer(ZenModelRM, ZenPackable):
49 """Manufacturer object""" 50 portal_type = meta_type = 'Manufacturer' 51 52 url = '' 53 supportNumber = '' 54 address1 = '' 55 address2 = '' 56 city = '' 57 state = '' 58 zip = '' 59 country = '' 60 regexes = () 61 62 _properties = ( 63 {'id':'url', 'type':'string', 'mode':'w'}, 64 {'id':'supportNumber', 'type':'string', 'mode':'w'}, 65 {'id':'address1', 'type':'string', 'mode':'w'}, 66 {'id':'address2', 'type':'string', 'mode':'w'}, 67 {'id':'city', 'type':'string', 'mode':'w'}, 68 {'id':'state', 'type':'string', 'mode':'w'}, 69 {'id':'zip', 'type':'string', 'mode':'w'}, 70 {'id':'country', 'type':'string', 'mode':'w'}, 71 {'id':'regexes', 'type':'lines', 'mode':'w'}, 72 ) 73 74 _relations = ZenPackable._relations + ( 75 ("products", ToManyCont(ToOne,"Products.ZenModel.ProductClass","manufacturer")), 76 ) 77 78 # Screen action bindings (and tab definitions) 79 factory_type_information = ( 80 { 81 'id' : 'Manufacturer', 82 'meta_type' : 'Manufacturer', 83 'description' : """Arbitrary device grouping class""", 84 'icon' : 'Manufacturer_icon.gif', 85 'product' : 'ZenModel', 86 'factory' : 'manage_addManufacturer', 87 'immediate_view' : 'viewManufacturerOverview', 88 'actions' : 89 ( 90 { 'id' : 'overview' 91 , 'name' : 'Overview' 92 , 'action' : 'viewManufacturerOverview' 93 , 'permissions' : (permissions.view, ) 94 }, 95 { 'id' : 'edit' 96 , 'name' : 'Edit' 97 , 'action' : 'editManufacturer' 98 , 'permissions' : ("Manage DMD", ) 99 }, 100 { 'id' : 'config' 101 , 'name' : 'Configuration Properties' 102 , 'action' : 'zPropertyEditNew' 103 , 'permissions' : ("Manage DMD",) 104 }, 105 { 'id' : 'viewHistory' 106 , 'name' : 'Modifications' 107 , 'action' : 'viewNewHistory' 108 , 'permissions' : (ZEN_VIEW_MODIFICATIONS,) 109 }, 110 ) 111 }, 112 ) 113 114 security = ClassSecurityInfo() 115 116
117 - def count(self):
118 """Return the number of products for this manufacturer. 119 """ 120 return self.products.countObjects()
121 122
123 - def manage_addHardware(self, prodName=None, REQUEST=None):
124 """Add a hardware product from UI code. 125 """ 126 if prodName: 127 from Products.ZenModel.HardwareClass import HardwareClass 128 self._getProduct(prodName, HardwareClass) 129 if REQUEST: return self.callZenScreen(REQUEST)
130 131
132 - def manage_addSoftware(self, prodName=None, isOS=False, REQUEST=None):
133 """Add a software product from UI code. 134 """ 135 if prodName: 136 from Products.ZenModel.SoftwareClass import SoftwareClass 137 prod = self._getProduct(prodName, SoftwareClass, isOS=isOS) 138 if REQUEST: return self.callZenScreen(REQUEST)
139 140
141 - def moveProducts(self, moveTarget=None, ids=None, REQUEST=None):
142 """Move product to different manufacturer. 143 """ 144 if not moveTarget or not ids: return self() 145 target = self.getManufacturer(moveTarget) 146 if isinstance(ids, basestring): ids = (ids,) 147 for id in ids: 148 obj = self.products._getOb(id) 149 obj._operation = 1 # moving object state 150 self.products._delObject(id) 151 target.products._setObject(id, obj) 152 if REQUEST: return self.callZenScreen(REQUEST)
153 154
155 - def _getProduct(self, prodName, factory, **kwargs):
156 """Add a product to this manufacturer based on its factory type. 157 """ 158 prod = self.products._getOb(prodName, None) 159 if not prod: 160 prod = factory(prodName) 161 for k, v in kwargs.iteritems(): 162 setattr(prod, k, v) 163 self.products._setObject(prod.id, prod) 164 prod = self.products._getOb(prod.id) 165 return prod
166 167
168 - def manage_deleteProducts(self, ids=None, REQUEST=None):
169 """Delete a list of products from UI. 170 """ 171 if not ids: return self.callZenScreen(REQUEST) 172 for id in ids: self.products._delObject(id) 173 if REQUEST: return self.callZenScreen(REQUEST)
174 175
176 - def getProductNames(self):
177 """return a list of all products this Manufacturer makes""" 178 prods = [""] 179 prods.extend(map(lambda x: x.getId(), 180 Manufacturer.products.objectValuesAll())) 181 prods.sort() 182 return prods
183 184
185 - def matches(self, name):
186 """ 187 Returns true if this manufacturer name or any of the regexes defined 188 match the provided string. 189 190 @param name: Manufacturer name 191 @type name: string 192 @return: True if this manufacturer matches the given name 193 @rtype: bool 194 """ 195 if self.id == name: 196 return True 197 for regex in self.regexes: 198 if re.search(regex, name): 199 return True 200 return False
201 202 203 security.declareProtected('Manage DMD', 'manage_editManufacturer')
204 - def manage_editManufacturer(self, id='', title='', url='', supportNumber='', 205 address1='', address2='', city='', state='', zip='', 206 country='', regexes=[], REQUEST=None):
207 """ 208 Edit a Manufacturer from a web page. 209 """ 210 redirect = self.rename(id) 211 self.title = title 212 self.url = url 213 self.supportNumber = supportNumber 214 self.address1 = address1 215 self.address2 = address2 216 self.city = city 217 self.state = state 218 self.zip = zip 219 self.country = country 220 self.regexes = regexes 221 if REQUEST: 222 from Products.ZenUtils.Time import SaveMessage 223 messaging.IMessageSender(self).sendToBrowser( 224 'Saved', 225 SaveMessage() 226 ) 227 return self.callZenScreen(REQUEST, redirect)
228 229 230 InitializeClass(Manufacturer) 231