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