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

# Source Code for Module Products.ZenModel.ProductClass

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