Back to index

plone3  3.1.7
Public Member Functions | Private Member Functions
plone.locking.browser.locking.LockingInformation Class Reference
Inheritance diagram for plone.locking.browser.locking.LockingInformation:
Inheritance graph
[legend]
Collaboration diagram for plone.locking.browser.locking.LockingInformation:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def is_locked
def is_locked_for_current_user
def lock_is_stealable
def lock_info

Private Member Functions

def _getNiceTimeDifference

Detailed Description

Lock information

Definition at line 34 of file locking.py.


Member Function Documentation

Definition at line 102 of file locking.py.

00102 
00103     def _getNiceTimeDifference(self, baseTime):
00104         now = DateTime()
00105         days = int(round(now - DateTime(baseTime)))
00106         delta = timedelta(now - DateTime(baseTime))
00107         days = delta.days
00108         hours = int(delta.seconds / 3600)
00109         minutes = (delta.seconds - (hours * 3600)) /60
00110 
00111         dateString = ""
00112         if days == 0:
00113             if hours == 0:
00114                 if delta.seconds < 120:
00115                     dateString = "1 minute"
00116                 else:
00117                     dateString = "%s minutes" % minutes
00118             elif hours == 1:
00119                 dateString = "%s hour and %s minutes" % (hours, minutes)
00120             else:
00121                 dateString = "%s hours and %s minutes" % (hours, minutes)
00122         else:
00123             if days == 1:
00124                 dateString = "%s day and %s hours" % (days, hours)
00125             else:
00126                 dateString = "%s days and %s hours" % (days, hours)
00127         return dateString

Here is the caller graph for this function:

Definition at line 38 of file locking.py.

00038 
00039     def is_locked(self):
00040         lockable = ILockable(aq_inner(self.context))
00041         return lockable.locked()

Here is the call graph for this function:

True if this object is locked for the current user (i.e. the
current user is not the lock owner)

Definition at line 42 of file locking.py.

00042 
00043     def is_locked_for_current_user(self):
00044         """True if this object is locked for the current user (i.e. the
00045         current user is not the lock owner)
00046         """
00047         lockable = ILockable(aq_inner(self.context))
00048         # Faster version - we rely on the fact that can_safely_unlock() is
00049         # True even if the object is not locked
00050         return not lockable.can_safely_unlock()
00051         # return lockable.locked() and not lockable.can_safely_unlock()

Here is the call graph for this function:

Get information about the current lock, a dict containing:

creator - the id of the user who created the lock
fullname - the full name of the lock creator
author_page - a link to the home page of the author
time - the creation time of the lock
time_difference - a string representing the time since the lock was
acquired.

Definition at line 58 of file locking.py.

00058 
00059     def lock_info(self):
00060         """Get information about the current lock, a dict containing:
00061 
00062         creator - the id of the user who created the lock
00063         fullname - the full name of the lock creator
00064         author_page - a link to the home page of the author
00065         time - the creation time of the lock
00066         time_difference - a string representing the time since the lock was
00067         acquired.
00068         """
00069 
00070         portal_membership = getToolByName(self.context, 'portal_membership')
00071         portal_url = getToolByName(self.context, 'portal_url')
00072         lockable = ILockable(aq_inner(self.context))
00073         url = portal_url()
00074         for info in lockable.lock_info():
00075             creator = info['creator']
00076             time = info['time']
00077             token = info['token']
00078             lock_type = info['type']
00079             # Get the fullname, but remember that the creator may not
00080             # be a member, but only Authenticated or even anonymous.
00081             # Same for the author_page
00082             fullname = ''
00083             author_page = ''
00084             member = portal_membership.getMemberById(creator)
00085             if member:
00086                 fullname = member.getProperty('fullname', '')
00087                 author_page = "%s/author/%s" % (url, creator)
00088             if fullname == '':
00089                 fullname = creator or _('label_an_anonymous_user',
00090                                         u'an anonymous user')
00091             time_difference = self._getNiceTimeDifference(time)
00092 
00093             return {
00094                 'creator'         : creator,
00095                 'fullname'        : fullname,
00096                 'author_page'     : author_page,
00097                 'time'            : time,
00098                 'time_difference' : time_difference,
00099                 'token'           : token,
00100                 'type'            : lock_type,
00101             }

Here is the call graph for this function:

Here is the caller graph for this function:

Find out if the lock is stealable

Definition at line 52 of file locking.py.

00052 
00053     def lock_is_stealable(self):
00054         """Find out if the lock is stealable
00055         """
00056         lockable = ILockable(self.context)
00057         return lockable.stealable()

Here is the call graph for this function:


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