1
2
3
4
5
6
7
8
9
10
11 __doc__="""Manufacturer
12
13 Manufacturer is a base class that represents a vendor of Products.
14
15 $Id: Manufacturer.py,v 1.11 2004/03/26 23:58:44 edahl Exp $"""
16
17 __version__ = "$Revision: 1.11 $"[11:-2]
18
19 import re
20
21 from Globals import DTMLFile, InitializeClass
22 from AccessControl import ClassSecurityInfo
23 from AccessControl import Permissions as permissions
24 from Products.ZenModel.ZenossSecurity import *
25 from Products.ZenWidgets import messaging
26 from Products.ZenUtils.deprecated import deprecated
27
28 from Products.ZenRelations.RelSchema import *
29
30 from ZenModelRM import ZenModelRM
31 from ZenPackable import ZenPackable
43
44 addManufacturer = DTMLFile('dtml/addManufacturer',globals())
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 country = ''
58 regexes = ()
59
60 _properties = (
61 {'id':'url', 'type':'string', 'mode':'w'},
62 {'id':'supportNumber', 'type':'string', 'mode':'w'},
63 {'id':'address1', 'type':'string', 'mode':'w'},
64 {'id':'address2', 'type':'string', 'mode':'w'},
65 {'id':'city', 'type':'string', 'mode':'w'},
66 {'id':'state', 'type':'string', 'mode':'w'},
67 {'id':'zip', 'type':'string', 'mode':'w'},
68 {'id':'country', 'type':'string', 'mode':'w'},
69 {'id':'regexes', 'type':'lines', 'mode':'w'},
70 )
71
72 _relations = ZenPackable._relations + (
73 ("products", ToManyCont(ToOne,"Products.ZenModel.ProductClass","manufacturer")),
74 )
75
76
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' : 'Configuration Properties'
100 , 'action' : 'zPropertyEditNew'
101 , 'permissions' : ("Manage DMD",)
102 },
103 )
104 },
105 )
106
107 security = ClassSecurityInfo()
108
109
111 """Return the number of products for this manufacturer.
112 """
113 return self.products.countObjects()
114
115
123
124
132
133
134 - def moveProducts(self, moveTarget=None, ids=None, REQUEST=None):
146
147
149 """Add a product to this manufacturer based on its factory type.
150 """
151 prod = self.products._getOb(prodName, None)
152 if not prod:
153 prodid = self.prepId(prodName)
154 prod = factory(prodid, **kwargs)
155 for k, v in kwargs.iteritems():
156 if not hasattr(prod, k):
157 setattr(prod, k, v)
158 self.products._setObject(prodid, prod)
159 prod = self.products._getOb(prodid)
160 return prod
161
162
169
170 @deprecated
172 """return a list of all products this Manufacturer makes"""
173 prods = [""]
174 prods.extend(map(lambda x: x.getId(),
175 self.products.objectValuesAll()))
176 prods.sort()
177 return prods
178
179
181 """
182 Returns true if this manufacturer name or any of the regexes defined
183 match the provided string.
184
185 @param name: Manufacturer name
186 @type name: string
187 @return: True if this manufacturer matches the given name
188 @rtype: bool
189 """
190 if self.id == name:
191 return True
192 for regex in self.regexes:
193 if re.search(regex, name):
194 return True
195 return False
196
197
198 security.declareProtected('Manage DMD', 'manage_editManufacturer')
199 - def manage_editManufacturer(self, id='', title='', url='', supportNumber='',
200 address1='', address2='', city='', state='', zip='',
201 country='', regexes=[], REQUEST=None):
223
224
225 InitializeClass(Manufacturer)
226