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

# Source Code for Module Products.ZenModel.Lockable

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