Back to index

plone3  3.1.7
Public Member Functions | Public Attributes | Private Member Functions | Private Attributes
plone.locking.lockable.TTWLockable Class Reference

List of all members.

Public Member Functions

def __init__
def lock
def unlock
def clear_locks
def locked
def can_safely_unlock
def stealable
def lock_info

Public Attributes

 context

Private Member Functions

def _locks

Private Attributes

 __locks

Detailed Description

An object that is being locked through-the-web

Definition at line 18 of file lockable.py.


Constructor & Destructor Documentation

def plone.locking.lockable.TTWLockable.__init__ (   self,
  context 
)

Definition at line 25 of file lockable.py.

00025 
00026     def __init__(self, context):
00027         self.context = context
00028         self.__locks = None
        

Here is the caller graph for this function:


Member Function Documentation

def plone.locking.lockable.TTWLockable._locks (   self,
  create = True 
) [private]

Definition at line 114 of file lockable.py.

00114 
00115     def _locks(self, create=True):
00116         if self.__locks is not None:
00117             return self.__locks
00118 
00119         annotations = IAnnotations(self.context)
00120         locks = annotations.get(ANNOTATION_KEY, None)
00121         if locks is None and create:
00122             locks = annotations.setdefault(ANNOTATION_KEY, PersistentDict())
00123         if locks is not None:
00124             self.__locks = locks
00125             return self.__locks
00126         else:
00127             return {}

Here is the caller graph for this function:

def plone.locking.lockable.TTWLockable.can_safely_unlock (   self,
  lock_type = STEALABLE_LOCK 
)

Definition at line 58 of file lockable.py.

00058 
00059     def can_safely_unlock(self, lock_type=STEALABLE_LOCK):
00060         if not lock_type.user_unlockable:
00061             return False
00062 
00063         info = self.lock_info()
00064         # There is no lock, so return True
00065         if len(info) == 0:
00066             return True
00067 
00068         userid = getSecurityManager().getUser().getId() or None
00069         for l in info:
00070             # There is another lock of a different type
00071             if not hasattr(l['type'], '__name__') or \
00072                l['type'].__name__ != lock_type.__name__:
00073                 return False
00074             # The lock is in fact held by the current user
00075             if l['creator'] == userid:
00076                 return True
00077         return False

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 51 of file lockable.py.

00051 
00052     def clear_locks(self):
00053         self.context.wl_clearLocks()
00054         self._locks().clear()

Here is the call graph for this function:

def plone.locking.lockable.TTWLockable.lock (   self,
  lock_type = STEALABLE_LOCK,
  children = False 
)

Definition at line 29 of file lockable.py.

00029 
00030     def lock(self, lock_type=STEALABLE_LOCK, children=False):
00031         if not self.locked():
00032             user = getSecurityManager().getUser()
00033             depth = children and 'infinity' or 0
00034             lock = LockItem(user, depth=depth, timeout=MAXTIMEOUT)
00035             token = lock.getLockToken()
00036             self.context.wl_setLock(token, lock)
00037 
00038             self._locks()[lock_type.__name__] = dict(type = lock_type,
00039                                                   token = token)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 95 of file lockable.py.

00095 
00096     def lock_info(self):
00097         info = []
00098         rtokens = dict([(v['token'], v['type']) for v in self._locks(False).values()])
00099         for lock in self.context.wl_lockValues(1):
00100             if not lock.isValid():
00101                 continue # Skip invalid/expired locks
00102             token = lock.getLockToken()
00103             creator = lock.getCreator()
00104             # creator can be None when locked by an anonymous user
00105             if creator is not None:
00106                 creator = creator[1]
00107             info.append({
00108                 'creator' : creator,
00109                 'time'    : lock.getModifiedTime(),
00110                 'token'   : token,
00111                 'type'    : rtokens.get(token, None),
00112             })
00113         return info

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 55 of file lockable.py.

00055 
00056     def locked(self):
00057         return bool(self.context.wl_isLocked())

Here is the caller graph for this function:

def plone.locking.lockable.TTWLockable.stealable (   self,
  lock_type = STEALABLE_LOCK 
)

Definition at line 78 of file lockable.py.

00078 
00079     def stealable(self, lock_type=STEALABLE_LOCK):
00080         # If the lock type is not stealable ever, return False
00081         if not lock_type.stealable:
00082             return False
00083         # Can't steal locks of a different type
00084         for l in self.lock_info():
00085             if not hasattr(l['type'], '__name__') or \
00086                l['type'].__name__ != lock_type.__name__:
00087                 return False
00088         # The lock type is stealable, and the object is not marked as 
00089         # non-stelaable, so return True
00090         if not INonStealableLock.providedBy(self.context):
00091             return True
00092         # Lock type is stealable, object is not stealable, but return True
00093         # anyway if we can safely unlock this object (e.g. we are the owner)
00094         return self.can_safely_unlock(lock_type)

Here is the call graph for this function:

Here is the caller graph for this function:

def plone.locking.lockable.TTWLockable.unlock (   self,
  lock_type = STEALABLE_LOCK,
  stealable_only = True 
)

Definition at line 40 of file lockable.py.

00040 
00041     def unlock(self, lock_type=STEALABLE_LOCK, stealable_only=True):
00042         if not self.locked():
00043             return
00044 
00045         if not lock_type.stealable or not stealable_only \
00046            or self.stealable(lock_type):
00047             key = self._locks().get(lock_type.__name__, None)
00048             if key:
00049                 self.context.wl_delLock(key['token'])
00050                 del self._locks()[lock_type.__name__]

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 27 of file lockable.py.

Definition at line 26 of file lockable.py.


The documentation for this class was generated from the following file: