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 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__="""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 types 
 23  import re 
 24   
 25  from Globals import DTMLFile, InitializeClass 
 26  from AccessControl import ClassSecurityInfo 
 27  from AccessControl import Permissions as permissions 
 28  from Products.ZenModel.ZenossSecurity import * 
 29  from Products.ZenWidgets import messaging 
 30   
 31  from Products.ZenRelations.RelSchema import * 
 32   
 33  from ZenModelRM import ZenModelRM 
 34  from ZenPackable import ZenPackable 
 35   
 36   
37 -def manage_addManufacturer(context, id=None, REQUEST = None):
38 """make a Manufacturer""" 39 if id: 40 d = Manufacturer(id) 41 context._setObject(id, d) 42 43 if REQUEST is not None: 44 REQUEST['RESPONSE'].redirect(context.absolute_url() 45 +'/manage_main')
46 47 addManufacturer = DTMLFile('dtml/addManufacturer',globals()) 48
49 -class Manufacturer(ZenModelRM, ZenPackable):
50 """Manufacturer object""" 51 portal_type = meta_type = 'Manufacturer' 52 53 url = '' 54 supportNumber = '' 55 address1 = '' 56 address2 = '' 57 city = '' 58 state = '' 59 zip = '' 60 country = '' 61 regexes = () 62 63 _properties = ( 64 {'id':'url', 'type':'string', 'mode':'w'}, 65 {'id':'supportNumber', 'type':'string', 'mode':'w'}, 66 {'id':'address1', 'type':'string', 'mode':'w'}, 67 {'id':'address2', 'type':'string', 'mode':'w'}, 68 {'id':'city', 'type':'string', 'mode':'w'}, 69 {'id':'state', 'type':'string', 'mode':'w'}, 70 {'id':'zip', 'type':'string', 'mode':'w'}, 71 {'id':'country', 'type':'string', 'mode':'w'}, 72 {'id':'regexes', 'type':'lines', 'mode':'w'}, 73 ) 74 75 _relations = ZenPackable._relations + ( 76 ("products", ToManyCont(ToOne,"Products.ZenModel.ProductClass","manufacturer")), 77 ) 78 79 # Screen action bindings (and tab definitions) 80 factory_type_information = ( 81 { 82 'id' : 'Manufacturer', 83 'meta_type' : 'Manufacturer', 84 'description' : """Arbitrary device grouping class""", 85 'icon' : 'Manufacturer_icon.gif', 86 'product' : 'ZenModel', 87 'factory' : 'manage_addManufacturer', 88 'immediate_view' : 'viewManufacturerOverview', 89 'actions' : 90 ( 91 { 'id' : 'overview' 92 , 'name' : 'Overview' 93 , 'action' : 'viewManufacturerOverview' 94 , 'permissions' : (permissions.view, ) 95 }, 96 { 'id' : 'edit' 97 , 'name' : 'Edit' 98 , 'action' : 'editManufacturer' 99 , 'permissions' : ("Manage DMD", ) 100 }, 101 { 'id' : 'config' 102 , 'name' : 'zProperties' 103 , 'action' : 'zPropertyEdit' 104 , 'permissions' : ("Manage DMD",) 105 }, 106 { 'id' : 'viewHistory' 107 , 'name' : 'Modifications' 108 , 'action' : 'viewHistory' 109 , 'permissions' : (ZEN_VIEW_MODIFICATIONS,) 110 }, 111 ) 112 }, 113 ) 114 115 security = ClassSecurityInfo() 116 117
118 - def count(self):
119 """Return the number of products for this manufacturer. 120 """ 121 return self.products.countObjects()
122 123
124 - def manage_addHardware(self, prodName=None, REQUEST=None):
125 """Add a hardware product from UI code. 126 """ 127 if prodName: 128 from Products.ZenModel.HardwareClass import HardwareClass 129 self._getProduct(prodName, HardwareClass) 130 if REQUEST: return self.callZenScreen(REQUEST)
131 132
133 - def manage_addSoftware(self, prodName=None, isOS=False, REQUEST=None):
134 """Add a software product from UI code. 135 """ 136 if prodName: 137 from Products.ZenModel.SoftwareClass import SoftwareClass 138 prod = self._getProduct(prodName, SoftwareClass) 139 prod.isOS = isOS 140 if REQUEST: return self.callZenScreen(REQUEST)
141 142
143 - def moveProducts(self, moveTarget=None, ids=None, REQUEST=None):
144 """Move product to different manufacturer. 145 """ 146 if not moveTarget or not ids: return self() 147 target = self.getManufacturer(moveTarget) 148 if type(ids) == types.StringType: ids = (ids,) 149 for id in ids: 150 obj = self.products._getOb(id) 151 obj._operation = 1 # moving object state 152 self.products._delObject(id) 153 target.products._setObject(id, obj) 154 if REQUEST: return self.callZenScreen(REQUEST)
155 156
157 - def _getProduct(self, prodName, factory):
158 """Add a product to this manufacturer based on its factory type. 159 """ 160 prod = self.products._getOb(prodName, None) 161 if not prod: 162 prod = factory(prodName) 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='', 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.url = url 212 self.supportNumber = supportNumber 213 self.address1 = address1 214 self.address2 = address2 215 self.city = city 216 self.state = state 217 self.zip = zip 218 self.country = country 219 self.regexes = regexes 220 if REQUEST: 221 from Products.ZenUtils.Time import SaveMessage 222 messaging.IMessageSender(self).sendToBrowser( 223 'Saved', 224 SaveMessage() 225 ) 226 return self.callZenScreen(REQUEST, redirect)
227 228 229 InitializeClass(Manufacturer) 230