本文整理汇总了Python中plone.locking.interfaces.ILockable类的典型用法代码示例。如果您正苦于以下问题:Python ILockable类的具体用法?Python ILockable怎么用?Python ILockable使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ILockable类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_lockinfo_tile
def test_lockinfo_tile(self):
self.other_browser.open(
self.pageURL +
'/@@plone.app.standardtiles.lockinfo'
)
self.assertIn('plone-lock-status', self.other_browser.contents)
root = fromstring(self.other_browser.contents)
nodes = root.xpath('//body//*[@id="plone-lock-status"]')
self.assertEqual(len(nodes), 1)
self.assertEqual(0, len(nodes[0].getchildren()))
# Then lock the page:
lockable = ILockable(self.page)
lockable.lock()
transaction.commit()
# The tile will show them:
self.other_browser.open(
self.pageURL +
'/@@plone.app.standardtiles.lockinfo'
)
self.assertIn('plone-lock-status', self.other_browser.contents)
root = fromstring(self.other_browser.contents)
nodes = root.xpath('//body//*[@id="plone-lock-status"]')
self.assertEqual(len(nodes), 1)
self.assertGreaterEqual(len(nodes[0].getchildren()), 1)
示例2: handleCancelCheckout
def handleCancelCheckout(event):
lockable = ILockable(event.object)
if lockable.locked():
# unlock working copy if it was auto-locked, or this will fail
lockable.clear_locks()
lock.unlockContext(event.baseline)
event.baseline.reindexObject(idxs=['review_state'])
示例3: test_locked_is_false_if_lock_is_invalid
def test_locked_is_false_if_lock_is_invalid(self):
create(Builder('lock')
.of_obj(self.wrapper)
.having(time=utcnow_tz_aware() - timedelta(seconds=800)))
lockable = ILockable(self.wrapper)
self.assertFalse(lockable.locked())
示例4: is_locked_by_another_user
def is_locked_by_another_user(self):
"""Return False if the document is locked by the current user or is
not locked at all, True otherwise.
"""
lockable = ILockable(self.context)
return not lockable.can_safely_unlock()
示例5: delete_unwanted_objects_from_memberfolder
def delete_unwanted_objects_from_memberfolder(portal,memberfolder,logger):
ct = getToolByName(portal,'portal_catalog')
strURL = "/".join(memberfolder.getPhysicalPath())
query = {'path':{'query':strURL},'portal_type':('Space','RecycleBin')}
objMemSpaces = [b.getObject() for b in ct(query)]
for o in objMemSpaces:
if callable(o.id):
o_id = o.id()
else:
o_id = o.id
try:
from plone.locking.interfaces import ILockable
lockable = ILockable(o)
was_locked = False
if lockable.locked():
was_locked = True
lockable.unlock()
parentItem = o.getParentNode()
parentItem.manage_delObjects(ids=[o_id])
transaction.savepoint()
except ComponentLookupError:
pass
logger.info("Deleted %s object from %s member folder." % (o_id, memberfolder.getId(),))
transaction.savepoint()
示例6: test_lockinfo_is_visible_for_lock_owner
def test_lockinfo_is_visible_for_lock_owner(self, browser):
self.login(self.regular_user, browser=browser)
browser.open(self.document)
self.assertEquals([], info_messages())
lockable = ILockable(self.document)
lockable.lock()
browser.open(self.document)
self.assertEquals([self.lock_message], info_messages())
示例7: is_available_for_current_user
def is_available_for_current_user(self):
"""Check whether the current meeting can be safely unlocked.
This means the current meeting is not locked by another user.
"""
lockable = ILockable(self.context)
return lockable.can_safely_unlock()
示例8: safe_unlock
def safe_unlock(self, redirect=True):
"""Unlock the object if the current user has the lock
"""
lockable = ILockable(self.context)
if lockable.can_safely_unlock():
lockable.unlock()
if redirect:
self.redirect()
示例9: testLockedItem
def testLockedItem(self):
membership_tool = getToolByName(self.folder, 'portal_membership')
membership_tool.addMember('anotherMember', 'secret', ['Member'], [])
locking = ILockable(self.folder.doc1)
locking.lock()
self.login('anotherMember')
actions = self.menu.getMenuItems(self.folder.doc1, self.request)
self.assertEqual(len(actions), 0)
示例10: is_locked_for_current_user
def is_locked_for_current_user(self):
"""True if this object is locked for the current user (i.e. the
current user is not the lock owner)
"""
lockable = ILockable(aq_inner(self.context))
# Faster version - we rely on the fact that can_safely_unlock() is
# True even if the object is not locked
return not lockable.can_safely_unlock()
示例11: test_unlock_button_is_visible_for_manager
def test_unlock_button_is_visible_for_manager(self, browser):
self.login(self.regular_user, browser=browser)
browser.open(self.document)
self.assertEquals([], info_messages())
lockable = ILockable(self.document)
lockable.lock()
self.login(self.manager, browser=browser)
browser.open(self.document)
self.assertEquals([self.lock_message + self.unlock_message], info_messages())
示例12: force_unlock
def force_unlock(self, redirect=True):
"""Steal the lock.
If redirect is True, redirect back to the context URL, i.e. reload
the page.
"""
lockable = ILockable(self.context)
lockable.unlock()
if redirect:
self.redirect()
示例13: test_refresh_locks_update_locks_to_current_time
def test_refresh_locks_update_locks_to_current_time(self):
lockable = ILockable(self.wrapper)
lockable.lock()
with freeze(pytz.UTC.localize(datetime(2015, 03, 10, 12, 05))):
lockable.refresh_lock()
lock = Lock.query.one()
self.assertEqual(
pytz.UTC.localize(datetime(2015, 03, 10, 12, 05)), lock.time)
示例14: step1andstep2
def step1andstep2(self):
"""Explore the site's content searching for misplaced content and move
it to its nearest translated parent.
"""
portal = getSite()
output = []
# Step 1 - Audit the content tree and make a list with the candidates
# to be moved to the right RLF. Once we get a candidate, decide if it
# should be moved to its nearest parent with the same language. Trying
# to avoid the catalog in order to avoid problems with big sites and
# bad or corrupted catalogs.
self.content_tree = []
self.findContent(portal, 0)
logger.info("Step 1: Eligible content: %s" % self.content_tree)
# We now have a list of lists that maps each eligible content with its
# depth in the content tree
# Step 2 - Move the eligible content to its nearest translated parent
# from the most deepest located content to the outer ones
self.content_tree.reverse()
for depth in self.content_tree:
if depth != []:
for content in depth:
parent = aq_parent(content)
target_folder = self.searchNearestTranslatedParent(content)
# Test if the id already exist previously
try:
cutted = parent.manage_cutObjects(content.getId())
except ResourceLockedError:
lockable = ILockable(content)
lockable.unlock()
cutted = parent.manage_cutObjects(content.getId())
try:
target_folder.manage_pasteObjects(cutted)
info_str = "Step 2: Moved object %s to folder %s" % (
'/'.join(content.getPhysicalPath()),
'/'.join(target_folder.getPhysicalPath()))
log = logger.info
except Exception as err:
info_str = "ERROR. Step 2: not possible to move " \
"object %s to folder %s. Error: %s" % (
'/'.join(content.getPhysicalPath()),
'/'.join(target_folder.getPhysicalPath()),
err)
log = logger.error
log(info_str)
output.append(info_str)
logger.info('Finished step 2')
return output
示例15: begin
def begin(self, formname, fieldname, structure='false'):
"""Begin inline editing - find the widget for the given field name
in the given form (looked up as a view on the context), then hide the
block with the id '${fieldname}-display' and display an edit form in
its place. If 'structure' is 'true' (a string), then the inline
editable field will eventually permit HTML input to be rendered
unescaped.
"""
context = aq_inner(self.context)
request = aq_inner(self.request)
form = getMultiAdapter((context, request), name=formname)
form = form.__of__(context)
if fieldname.startswith(form.prefix):
fieldname = fieldname[len(form.prefix)+1:]
formlib_field = form.form_fields[fieldname]
widgets = formlib.setUpEditWidgets((formlib_field,), form.prefix,
context, request, ignore_request=True)
widget = widgets[fieldname]
display_id = '%s-display' % fieldname
form_id = '%s-form' % fieldname
ksscore = self.getCommandSet('core')
zopecommands = self.getCommandSet('zope')
plonecommands = self.getCommandSet('plone')
# lock the context (or issue warning)
locking = ILockable(context, None)
if locking:
if not locking.can_safely_unlock():
selector = ksscore.getHtmlIdSelector('plone-lock-status')
zopecommands.refreshViewlet(selector, 'plone.abovecontent', 'plone.lockinfo')
plonecommands.refreshContentMenu()
return
else: # we are locking the content
locking.lock()
plonecommands.issuePortalMessage('')
# hide the existing display field
display_selector = ksscore.getHtmlIdSelector(display_id)
ksscore.addClass(display_selector, 'hiddenStructure')
# show the form
form_html = self.form_template(widget=widget,
form_id=form_id,
fieldname=fieldname,
structure=structure)
ksscore.insertHTMLAfter(display_selector, form_html)