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

# Source Code for Module Products.ZenModel.Lockable

      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  from Products.ZenWidgets import messaging
     12
     13  UNLOCKED = 0
     14  DELETE_LOCKED = 1
     15  UPDATE_LOCKED = 2
     16
     17
     18 -class Lockable(object):
     19
     20      sendEventWhenBlockedFlag = False
     21      modelerLock = UNLOCKED
     22
     23 -    def getNextLockableParent(self, obj=None):
     24          if not obj: obj = self
     25          if obj.getPrimaryParent() == self.getDmd():
     26              return None
     27          elif isinstance(obj.getPrimaryParent(), Lockable):
     28              return obj.getPrimaryParent()
     29          else:
     30              return self.getNextLockableParent(obj.getPrimaryParent())
     31
     32 -    def sendEventWhenBlocked(self):
     33          if self.sendEventWhenBlockedFlag:
     34              return True
     35          return False
     36          '''
     37          else:
     38              lockableParent = self.getNextLockableParent()
     39              if lockableParent:
     40                  return lockableParent.sendEventWhenBlocked()
     41              else:
     42                  return False
     43          '''
     44
     45 -    def isUnlocked(self):
     46          if self.modelerLock == UNLOCKED:
     47                  return True
     48          return False
     49
     50 -    def isLockedFromDeletion(self):
     51          if (self.modelerLock == DELETE_LOCKED
     52              or self.modelerLock == UPDATE_LOCKED):
     53              return True
     54          return False
     55          '''
     56          else:
     57              lockableParent = self.getNextLockableParent()
     58              if lockableParent:
     59                  return lockableParent.isLockedFromDeletion()
     60              else:
     61                  return False
     62          '''
     63
     64 -    def isLockedFromUpdates(self):
     65          if self.modelerLock == UPDATE_LOCKED:
     66              return True
     67          return False
     68          '''
     69          else:
     70              lockableParent = self.getNextLockableParent()
     71              if lockableParent:
     72                  return lockableParent.isLockedFromUpdates()
     73              else:
     74                  return False
     75          '''
     76
     77 -    def setSendEventWhenBlockedFlag(self):
     78          self.sendEventWhenBlockedFlag = True
     79
     80 -    def unsetSendEventWhenBlockedFlag(self):
     81          self.sendEventWhenBlockedFlag = False
     82
     83 -    def unlock(self, REQUEST=None):
     84          """Unlock object"""
     85          self.modelerLock = UNLOCKED
     86          self.unsetSendEventWhenBlockedFlag()
     87
     88          if self.meta_type == 'Device':
     89              for dc in self.getDeviceComponents():
     90                  dc.unlock()
     91
     92          if REQUEST:
     93              messaging.IMessageSender(self).sendToBrowser(
     94                  'Unlocked',
     95                  '%s has been unlocked.' % self.id
     96              )
     97              return self.callZenScreen(REQUEST)
     98
     99 -    def lockFromDeletion(self, sendEventWhenBlocked=None, REQUEST=None):
    100          """Lock object from being deleted"""
    101          self.modelerLock = DELETE_LOCKED
    102          if sendEventWhenBlocked:
    103              self.setSendEventWhenBlockedFlag()
    104          else:
    105              self.unsetSendEventWhenBlockedFlag()
    106
    107          if self.meta_type == 'Device':
    108              for dc in self.getDeviceComponents():
    109                  dc.lockFromDeletion(sendEventWhenBlocked)
    110
    111          if REQUEST:
    112              messaging.IMessageSender(self).sendToBrowser(
    113                  'Locked',
    114                  '%s has been locked from deletion.' % self.id
    115              )
    116              return self.callZenScreen(REQUEST)
    117
    118 -    def lockFromUpdates(self, sendEventWhenBlocked=None, REQUEST=None):
    119          """Lock object from being deleted or updated"""
    120          self.modelerLock = UPDATE_LOCKED
    121          if sendEventWhenBlocked:
    122              self.setSendEventWhenBlockedFlag()
    123          else:
    124              self.unsetSendEventWhenBlockedFlag()
    125
    126          if self.meta_type == 'Device':
    127              for dc in self.getDeviceComponents():
    128                  dc.lockFromUpdates(sendEventWhenBlocked)
    129
    130          if REQUEST:
    131              messaging.IMessageSender(self).sendToBrowser(
    132                  'Locked',
    133                  '%s has been locked from updates and deletion.' % self.id
    134              )
    135              return self.callZenScreen(REQUEST)
    136
    137 -    def lockStatus(self):
    138          '''
    139          if self.modelerLock == DELETE_LOCKED:
    140              return "Locked from deletion"
    141          elif self.modelerLock == UPDATE_LOCKED:
    142              return "Locked from updates and deletion"
    143          elif isinstance(self.getPrimaryParent(), Lockable):
    144              return "%s by parent" % self.getPrimaryParent().lockStatus()
    145          elif self.modelerLock == UNLOCKED:
    146              return "Unlocked"
    147          '''
    148          if self.isLockedFromUpdates():
    149              return "locked from updates and deletion"
    150          elif self.isLockedFromDeletion():
    151              return "locked from deletion"
    152          else:
    153              return "unlocked"
    154
    155 -    def lockWarning(self):
    156          if self.sendEventWhenBlocked():
    157              return "Send event when blocked"
    158          else:
    159              return "Do not send event when blocked"
    160