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

# Source Code for Module Products.ZenModel.Manufacturer

      1  ##############################################################################
      2  #
      3  # Copyright (C) Zenoss, Inc. 2007, 2009, 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__="""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
     32
     33
     34 -def manage_addManufacturer(context, id=None, REQUEST = None):
     35      """make a Manufacturer"""
     36      if id:
     37          d = Manufacturer(id)
     38          context._setObject(id, d)
     39
     40      if REQUEST is not None:
     41          REQUEST['RESPONSE'].redirect(context.absolute_url()
     42                                       +'/manage_main')
     43
     44  addManufacturer = DTMLFile('dtml/addManufacturer',globals())
     45
     46 -class Manufacturer(ZenModelRM, ZenPackable):
     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      # Screen action bindings (and tab definitions)
     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
    110 -    def count(self):
    111          """Return the number of products for this manufacturer.
    112          """
    113          return self.products.countObjects()
    114
    115
    116 -    def manage_addHardware(self, prodName=None, REQUEST=None):
    117          """Add a hardware product from UI code.
    118          """
    119          if prodName:
    120              from Products.ZenModel.HardwareClass import HardwareClass
    121              self._getProduct(prodName, HardwareClass)
    122          if REQUEST: return self.callZenScreen(REQUEST)
    123
    124
    125 -    def manage_addSoftware(self, prodName=None, isOS=False, REQUEST=None):
    126          """Add a software product from UI code.
    127          """
    128          if prodName:
    129              from Products.ZenModel.SoftwareClass import SoftwareClass
    130              prod = self._getProduct(prodName, SoftwareClass, isOS=isOS)
    131          if REQUEST: return self.callZenScreen(REQUEST)
    132
    133
    134 -    def moveProducts(self, moveTarget=None, ids=None, REQUEST=None):
    135          """Move product to different manufacturer.
    136          """
    137          if not moveTarget or not ids: return self()
    138          target = self.getManufacturer(moveTarget)
    139          if isinstance(ids, basestring): ids = (ids,)
    140          for id in ids:
    141              obj = self.products._getOb(id)
    142              obj._operation = 1 # moving object state
    143              self.products._delObject(id)
    144              target.products._setObject(id, obj)
    145          if REQUEST: return self.callZenScreen(REQUEST)
    146
    147
    148 -    def _getProduct(self, prodName, factory, **kwargs):
    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
    163 -    def manage_deleteProducts(self, ids=None, REQUEST=None):
    164          """Delete a list of products from UI.
    165          """
    166          if not ids: return self.callZenScreen(REQUEST)
    167          for id in ids: self.products._delObject(id)
    168          if REQUEST: return self.callZenScreen(REQUEST)
    169
    170      @deprecated
    171 -    def getProductNames(self):
    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
    180 -    def matches(self, name):
    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):
    202          """
    203          Edit a Manufacturer from a web page.
    204          """
    205          redirect = self.rename(id)
    206          self.title = title
    207          self.url = url
    208          self.supportNumber = supportNumber
    209          self.address1 = address1
    210          self.address2 = address2
    211          self.city = city
    212          self.state = state
    213          self.zip = zip
    214          self.country = country
    215          self.regexes = regexes
    216          if REQUEST:
    217              from Products.ZenUtils.Time import SaveMessage
    218              messaging.IMessageSender(self).sendToBrowser(
    219                  'Saved',
    220                  SaveMessage()
    221              )
    222              return self.callZenScreen(REQUEST, redirect)
    223
    224
    225  InitializeClass(Manufacturer)
    226