Package Products :: Package ZenModel :: Module ProductClass |
[hide private]
[frames] | no frames]

# Source Code for Module Products.ZenModel.ProductClass

      1  ##############################################################################
      2  #
      3  # Copyright (C) Zenoss, Inc. 2007, all rights reserved.
      4  #
      5  # This content is made available according to terms specified in
      6  # License.zenoss under the directory where your Zenoss product is installed.
      7  #
      8  ##############################################################################
      9
     10
     11  __doc__="""ProductClass
     12
     13  The product classification class.  default identifiers, screens,
     14  and data collectors live here.
     15
     16  $Id: ProductClass.py,v 1.10 2004/03/26 23:58:44 edahl Exp $"""
     17
     18  __version__ = "$Revision: 1.10 $"[11:-2]
     19
     20  from Globals import InitializeClass
     21  from AccessControl import ClassSecurityInfo
     22  from AccessControl import Permissions as permissions
     23  from zope.interface import implements
     24
     25  from Products.ZenModel.interfaces import IIndexed
     26  from Products.ZenModel.ZenossSecurity import *
     27  from Products.ZenWidgets import messaging
     28
     29  from ZenModelRM import ZenModelRM
     30  from ZenPackable import ZenPackable
     31
     32  from Products.ZenRelations.RelSchema import *
     33
     34 -class ProductClass(ZenModelRM, ZenPackable):
     35      implements(IIndexed)
     36      meta_type = "ProductClass"
     37
     38      #itclass = ""
     39      name = ""
     40      productKeys = []
     41      isOS = False
     42
     43      default_catalog = "productSearch"
     44
     45      _properties = (
     46          #{'id':'itclass', 'type':'string', 'mode':'w'},
     47          {'id':'name', 'type':'string', 'mode':'w'},
     48          {'id':'productKeys', 'type':'lines', 'mode':'w'},
     49          {'id':'partNumber', 'type':'string', 'mode':'w'},
     50          {'id':'description', 'type':'string', 'mode':'w'},
     51          {'id':'isOS', 'type':'boolean', 'mode':'w'},
     52      )
     53
     54      _relations = ZenPackable._relations + (
     55          ("instances", ToMany(ToOne, "Products.ZenModel.MEProduct", "productClass")),
     56          ("manufacturer", ToOne(ToManyCont,"Products.ZenModel.Manufacturer","products")),
     57      )
     58
     59      factory_type_information = (
     60          {
     61              'id'             : 'ProductClass',
     62              'meta_type'      : 'ProductClass',
     63              'description'    : """Class to manage product information""",
     64              'icon'           : 'ProductClass.gif',
     65              'product'        : 'ZenModel',
     66              'factory'        : 'manage_addProductClass',
     67              'immediate_view' : 'viewProductClassOverview',
     68              'actions'        :
     69              (
     70                  { 'id'            : 'overview'
     71                  , 'name'          : 'Overview'
     72                  , 'action'        : 'viewProductClassOverview'
     73                  , 'permissions'   : (
     74                    permissions.view, )
     75                  },
     76                  { 'id'            : 'edit'
     77                  , 'name'          : 'Edit'
     78                  , 'action'        : 'editProductClass'
     79                  , 'permissions'   : ("Manage DMD", )
     80                  },
     81                  { 'id'            : 'config'
     82                  , 'name'          : 'Configuration Properties'
     83                  , 'action'        : 'zPropertyEditNew'
     84                  , 'permissions'   : ("Manage DMD",)
     85                  },
     86              )
     87            },
     88          )
     89
     90      security = ClassSecurityInfo()
     91
     92
     93 -    def __init__(self, id, title="", prodName=None,
     94                   productKey=None, partNumber="",description=""):
     95          ZenModelRM.__init__(self, id, title)
     96          # XXX per a comment in #406 from Erik, we may want to get rid
     97          # of prodName and only use productKey, to avoid redundancy
     98          if productKey:
     99              self.productKeys = [productKey]
    100          elif prodName:
    101              self.productKeys = [prodName]
    102          else:
    103              # When adding manually through the gui both prodName and
    104              # productKey will be None
    105              self.productKeys = []
    106          if prodName is None:  self.name = id
    107          else: self.name = prodName
    108          self.partNumber = partNumber
    109          self.description = description
    110
    111
    112 -    def type(self):
    113          """Return the type name of this product (Hardware, Software).
    114          """
    115          return self.meta_type[:-5]
    116
    117
    118 -    def count(self):
    119          """Return the number of existing instances for this class.
    120          """
    121          return self.instances.countObjects()
    122
    123
    124 -    def getProductKey(self):
    125          """Return the first product key of the device.
    126          """
    127          if len(self.productKeys) > 0:
    128              return self.productKeys[0]
    129          return ""
    130
    131
    132 -    def getManufacturerName(self):
    133          if not self.manufacturer():
    134              return ''
    135          return self.manufacturer().getId()
    136
    137
    138      security.declareProtected('Manage DMD', 'manage_editProductClass')
    139 -    def manage_editProductClass(self, name="", productKeys=(), isOS=False,
    140                                 partNumber="", description="", REQUEST=None):
    141          """
    142          Edit a ProductClass from a web page.
    143          """
    144          redirect = self.rename(name)
    145          productKeys = [ l.strip() for l in productKeys.split('\n') ]
    146          if productKeys != self.productKeys:
    147              self.unindex_object()
    148              self.productKeys = productKeys
    149          self.partNumber = partNumber
    150          self.description = description
    151          self.isOS = isOS
    152          self.name = name
    153          self.index_object()
    154          if REQUEST:
    155              from Products.ZenUtils.Time import SaveMessage
    156              messaging.IMessageSender(self).sendToBrowser(
    157                  'Product Class Saved',
    158                  SaveMessage()
    159              )
    160              return self.callZenScreen(REQUEST, redirect)
    161
    162
    163  InitializeClass(ProductClass)
    164