[CMF-checkins] CVS: CMF/CMFStaging - LockTool.py:1.14
Shane Hathaway
shane at zope.com
Tue Jan 13 16:45:38 EST 2004
Update of /cvs-repository/CMF/CMFStaging
In directory cvs.zope.org:/tmp/cvs-serv8650
Modified Files:
LockTool.py
Log Message:
Added autolock(), which locks an object implicitly if possible.
Also added code suggested by gregweb at dplanet.ch that prevents
auto-checkin when the object is already checked in.
=== CMF/CMFStaging/LockTool.py 1.13 => 1.14 ===
--- CMF/CMFStaging/LockTool.py:1.13 Mon Oct 27 15:21:53 2003
+++ CMF/CMFStaging/LockTool.py Tue Jan 13 16:45:37 2004
@@ -21,6 +21,7 @@
import os
+from Acquisition import aq_parent
from Globals import InitializeClass, DTMLFile
from AccessControl import ClassSecurityInfo, getSecurityManager
from Products.CMFCore.utils import UniqueObject, getToolByName, \
@@ -29,6 +30,7 @@
ModifyPortalContent
from webdav.WriteLockInterface import WriteLockInterface
from webdav.LockItem import LockItem
+from zExceptions import Unauthorized
from staging_utils import verifyPermission
@@ -103,6 +105,19 @@
obj.wl_setLock(lockitem.getLockToken(), lockitem)
+ security.declarePublic('autolock')
+ def autolock(self, obj=None):
+ """Tries to lock an object, swallowing LockingErrors and Unauthorized.
+ """
+ if obj is None:
+ obj = aq_parent(self)
+ try:
+ self.lock(obj)
+ except (LockingError, Unauthorized):
+ return 0
+ return 1
+
+
security.declarePublic('breaklock')
def breaklock(self, obj, message=''):
"""Breaks the lock in an emergency.
@@ -113,7 +128,9 @@
if self.auto_version:
vt = getToolByName(self, 'portal_versions', None)
if vt is not None:
- vt.checkin(obj, message)
+ if (vt.isUnderVersionControl(obj)
+ and vt.isCheckedOut(obj)):
+ vt.checkin(obj, message)
security.declarePublic('unlock')
@@ -138,7 +155,9 @@
if self.auto_version:
vt = getToolByName(self, 'portal_versions', None)
if vt is not None:
- vt.checkin(obj, message)
+ if (vt.isUnderVersionControl(obj)
+ and vt.isCheckedOut(obj)):
+ vt.checkin(obj, message)
security.declarePublic('locker')
More information about the CMF-checkins
mailing list