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

Source Code for Module ZenModel.Manufacturer

  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__="""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   
 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 61 _properties = ( 62 {'id':'url', 'type':'string', 'mode':'w'}, 63 {'id':'supportNumber', 'type':'string', 'mode':'w'}, 64 {'id':'address1', 'type':'string', 'mode':'w'}, 65 {'id':'address2', 'type':'string', 'mode':'w'}, 66 {'id':'city', 'type':'string', 'mode':'w'}, 67 {'id':'state', 'type':'string', 'mode':'w'}, 68 {'id':'zip', 'type':'string', 'mode':'w'}, 69 {'id':'country', 'type':'string', 'mode':'w'}, 70 ) 71 72 _relations = ZenPackable._relations + ( 73 ("products", ToManyCont(ToOne,"Products.ZenModel.ProductClass","manufacturer")), 74 ) 75 76 # Screen action bindings (and tab definitions) 77 factory_type_information = ( 78 { 79 'id' : 'Manufacturer', 80 'meta_type' : 'Manufacturer', 81 'description' : """Arbitrary device grouping class""", 82 'icon' : 'Manufacturer_icon.gif', 83 'product' : 'ZenModel', 84 'factory' : 'manage_addManufacturer', 85 'immediate_view' : 'viewManufacturerOverview', 86 'actions' : 87 ( 88 { 'id' : 'overview' 89 , 'name' : 'Overview' 90 , 'action' : 'viewManufacturerOverview' 91 , 'permissions' : (permissions.view, ) 92 }, 93 { 'id' : 'edit' 94 , 'name' : 'Edit' 95 , 'action' : 'editManufacturer' 96 , 'permissions' : ("Manage DMD", ) 97 }, 98 { 'id' : 'config' 99 , 'name' : 'zProperties' 100 , 'action' : 'zPropertyEdit' 101 , 'permissions' : ("Manage DMD",) 102 }, 103 { 'id' : 'viewHistory' 104 , 'name' : 'Modifications' 105 , 'action' : 'viewHistory' 106 , 'permissions' : (ZEN_VIEW_MODIFICATIONS,) 107 }, 108 ) 109 }, 110 ) 111 112 security = ClassSecurityInfo() 113 114
115 - def count(self):
116 """Return the number of products for this manufacturer. 117 """ 118 return self.products.countObjects()
119 120
121 - def manage_addHardware(self, prodName=None, REQUEST=None):
122 """Add a hardware product from UI code. 123 """ 124 if prodName: 125 from Products.ZenModel.HardwareClass import HardwareClass 126 self._getProduct(prodName, HardwareClass) 127 if REQUEST: return self.callZenScreen(REQUEST)
128 129
130 - def manage_addSoftware(self, prodName=None, isOS=False, REQUEST=None):
131 """Add a software product from UI code. 132 """ 133 if prodName: 134 from Products.ZenModel.SoftwareClass import SoftwareClass 135 prod = self._getProduct(prodName, SoftwareClass) 136 prod.isOS = isOS 137 if REQUEST: return self.callZenScreen(REQUEST)
138 139
140 - def moveProducts(self, moveTarget=None, ids=None, REQUEST=None):
141 """Move product to different manufacturer. 142 """ 143 if not moveTarget or not ids: return self() 144 target = self.getManufacturer(moveTarget) 145 if type(ids) == types.StringType: ids = (ids,) 146 for id in ids: 147 obj = self.products._getOb(id) 148 obj._operation = 1 # moving object state 149 self.products._delObject(id) 150 target.products._setObject(id, obj) 151 if REQUEST: return self.callZenScreen(REQUEST)
152 153
154 - def _getProduct(self, prodName, factory):
155 """Add a product to this manufacturer based on its factory type. 156 """ 157 prod = self._getOb(prodName, None) 158 if not prod: 159 prod = factory(prodName) 160 self.products._setObject(prod.id, prod) 161 prod = self.products._getOb(prod.id) 162 return prod
163 164
165 - def manage_deleteProducts(self, ids=None, REQUEST=None):
166 """Delete a list of products from UI. 167 """ 168 if not ids: return self.callZenScreen(REQUEST) 169 for id in ids: self.products._delObject(id) 170 if REQUEST: return self.callZenScreen(REQUEST)
171 172
173 - def getProductNames(self):
174 """return a list of all products this Manufacturer makes""" 175 prods = [""] 176 prods.extend(map(lambda x: x.getId(), 177 Manufacturer.products.objectValuesAll())) 178 prods.sort() 179 return prods
180 181 182 security.declareProtected('Manage DMD', 'manage_editManufacturer')
183 - def manage_editManufacturer(self, id='', 184 url = '', supportNumber = '', 185 address1 = '', address2 = '', 186 city = '', state = '', zip = '', country = '', REQUEST=None):
187 """ 188 Edit a Manufacturer from a web page. 189 """ 190 redirect = self.rename(id) 191 self.url = url 192 self.supportNumber = supportNumber 193 self.address1 = address1 194 self.address2 = address2 195 self.city = city 196 self.state = state 197 self.zip = zip 198 self.country = country 199 if REQUEST: 200 from Products.ZenUtils.Time import SaveMessage 201 messaging.IMessageSender(self).sendToBrowser( 202 'Saved', 203 SaveMessage() 204 ) 205 return self.callZenScreen(REQUEST, redirect)
206 207 208 InitializeClass(Manufacturer) 209