1
2
3
4
5
6
7
8
9
10
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
45
46 addManufacturer = DTMLFile('dtml/addManufacturer',globals())
47
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
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 )
106 },
107 )
108
109 security = ClassSecurityInfo()
110
111
113 """Return the number of products for this manufacturer.
114 """
115 return self.products.countObjects()
116
117
125
126
134
135
136 - def moveProducts(self, moveTarget=None, ids=None, REQUEST=None):
148
149
151 """Add a product to this manufacturer based on its factory type.
152 """
153 prod = self.products._getOb(prodName, None)
154 if not prod:
155 prod = factory(prodName)
156 for k, v in kwargs.iteritems():
157 setattr(prod, k, v)
158 self.products._setObject(prod.id, prod)
159 prod = self.products._getOb(prod.id)
160 return prod
161
162
169
170
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
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