1
2
3
4
5
6
7
8
9
10
11 __doc__="""ClassifierEntry
12
13 Contains a list of keywords that are used to match an entry to a specific
14 device. Once a match is found the Entry provides paths for DeviceClass,
15 Product, and Company. This could potentially also provide Location, System
16 Group etc.
17
18 $Id: ClassifierEntry.py,v 1.6 2004/03/26 23:58:44 edahl Exp $"""
19
20 __version__ = "$Revision: 1.6 $"[11:-2]
21
22 from AccessControl import ClassSecurityInfo
23 from Globals import DTMLFile
24
25 from Products.ZCatalog.CatalogAwareness import CatalogAware
26 from OFS.SimpleItem import SimpleItem
27 from OFS.PropertyManager import PropertyManager
28
29
30 -def manage_addClassifierEntry(context, id=None, title=None,
31 default_catalog = "", keywords = "", deviceClassPath = "",
32 product = "", systemPath = "",
33 locationPath = "", manufacturer = "",
34 productDescr = "", REQUEST = None):
35 """make a device"""
36 if not id:
37 id = context.ZenClassifier.getNextClassifierEntryId()
38 ce = ClassifierEntry(id, title=title,
39 default_catalog=default_catalog,
40 keywords=keywords, deviceClassPath=deviceClassPath,
41 product=product, systemPath=systemPath,
42 locationPath=locationPath, manufacturer=manufacturer,
43 productDescr = productDescr)
44 context._setObject(id, ce)
45 ce = context._getOb(id)
46
47 if REQUEST is not None:
48 REQUEST['RESPONSE'].redirect(context.absolute_url()
49 +'/manage_main')
50
51
52 addClassifierEntry = DTMLFile('dtml/addClassifierEntry',globals())
53
54 -class ClassifierEntry(PropertyManager, CatalogAware, SimpleItem):
55 """ClassifierEntry"""
56
57 meta_type = 'ClassifierEntry'
58
59 manage_options = (PropertyManager.manage_options +
60 SimpleItem.manage_options
61 )
62
63 _properties = (
64 {'id':'default_catalog', 'type':'selection',
65 'select_variable':'getClassifierNames'},
66 {'id':'keywords', 'type':'text', 'mode':'rw'},
67 {'id':'deviceClassPath', 'type':'string', 'mode':'rw'},
68 {'id':'manufacturer', 'type':'string', 'mode':'rw'},
69 {'id':'product', 'type':'string', 'mode':'rw'},
70 {'id':'productDescr', 'type':'text', 'mode':'rw'},
71 )
72
73
74 security = ClassSecurityInfo()
75
76 - def __init__(self, id, title=None,
77 default_catalog = "", keywords = "", deviceClassPath = "",
78 product = "", systemPath = "",
79 locationPath = "", manufacturer = "",
80 snmpAgentPath = "", productDescr = ""):
81 from Products.ZenUtils.Utils import unused
82 unused(locationPath)
83 self.id = id
84 self.title = title
85 self.default_catalog = default_catalog
86 self.keywords = keywords
87 self.deviceClassPath = deviceClassPath
88 self.product = product
89 self.productDescr = productDescr
90 self.systemPath = systemPath
91 self.snmpAgentPath = snmpAgentPath
92 self.manufacturer = manufacturer
93
94
95
96 - def manage_editProperties(self, REQUEST):
97 """ Added indexing call -EAD
98 Edit object properties via the web.
99 The purpose of this method is to change all property values,
100 even those not listed in REQUEST; otherwise checkboxes that
101 get turned off will be ignored. Use manage_changeProperties()
102 instead for most situations.
103 """
104 for prop in self._propertyMap():
105 name=prop['id']
106 if 'w' in prop.get('mode', 'wd'):
107 value=REQUEST.get(name, '')
108 if name == 'default_catalog' and self.default_catalog != value:
109 self.unindex_object()
110 self._updateProperty(name, value)
111 self.index_object()
112 if REQUEST:
113 message="Saved changes."
114 return self.manage_propertiesForm(self,REQUEST,
115 manage_tabs_message=message)
116
117
119 return "/".join(self.getPhysicalPath())
120
121
122 - def index_object(self):
123 """Override so that we can find the catalog no matter where we are
124 A common method to allow Findables to index themselves."""
125 if hasattr(self.ZenClassifier, self.default_catalog):
126 cat = getattr(self.ZenClassifier, self.default_catalog)
127 cat.catalog_object(self, self._url())
128
129
130 - def unindex_object(self):
131 """Override so that we can find the catalog no matter where we are
132 A common method to allow Findables to unindex themselves."""
133 if hasattr(self.ZenClassifier, self.default_catalog):
134 cat = getattr(self.ZenClassifier, self.default_catalog)
135 cat.uncatalog_object(self._url())
136
137
139 """allow select in property manager to find ZenClassifier"""
140 return self.ZenClassifier.getClassifierNames()
141
142
143 - def getKeywords(self):
144 """base class just returns attribute mobile subclass returns
145 a concatination of all keyword values up its aquisition path"""
146 return self.keywords
147
148
150 """base class just returns attribute mobile subclass returns
151 builds its path based on its current aquisition path"""
152 return self.deviceClassPath
153
154
155 - def getProduct(self):
156 """return the product path for this classifier entry"""
157 return self.product
158
159
160 - def getManufacturer(self):
161 """return the manufacturer for this classifier entry"""
162 return self.manufacturer
163
164 - def getProductDescr(self):
165 """return the productDescr for this classifier entry"""
166 return self.productDescr
167