本文整理汇总了Python中plone.locking.interfaces.ILockable.lock方法的典型用法代码示例。如果您正苦于以下问题:Python ILockable.lock方法的具体用法?Python ILockable.lock怎么用?Python ILockable.lock使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类plone.locking.interfaces.ILockable
的用法示例。
在下文中一共展示了ILockable.lock方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_clear_locks_remove_all_locks_on_the_object
# 需要导入模块: from plone.locking.interfaces import ILockable [as 别名]
# 或者: from plone.locking.interfaces.ILockable import lock [as 别名]
def test_clear_locks_remove_all_locks_on_the_object(self):
lockable = ILockable(self.wrapper)
lockable.lock()
self.assertTrue(lockable.locked())
lockable.clear_locks()
self.assertFalse(lockable.locked())
示例2: test_lockinfo_tile
# 需要导入模块: from plone.locking.interfaces import ILockable [as 别名]
# 或者: from plone.locking.interfaces.ILockable import lock [as 别名]
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)
示例3: test_lockinfo_is_visible_for_lock_owner
# 需要导入模块: from plone.locking.interfaces import ILockable [as 别名]
# 或者: from plone.locking.interfaces.ILockable import lock [as 别名]
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())
示例4: testLockedItem
# 需要导入模块: from plone.locking.interfaces import ILockable [as 别名]
# 或者: from plone.locking.interfaces.ILockable import lock [as 别名]
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)
示例5: test_unlock_button_is_visible_for_manager
# 需要导入模块: from plone.locking.interfaces import ILockable [as 别名]
# 或者: from plone.locking.interfaces.ILockable import lock [as 别名]
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())
示例6: test_unlock_does_not_check_if_lock_is_stealable_when_stealable_only_is_false
# 需要导入模块: from plone.locking.interfaces import ILockable [as 别名]
# 或者: from plone.locking.interfaces.ILockable import lock [as 别名]
def test_unlock_does_not_check_if_lock_is_stealable_when_stealable_only_is_false(self):
lockable = ILockable(self.wrapper)
lockable.lock()
# manually change lock creator
lock = Lock.query.first()
lock.creator = 'other-user'
lockable.unlock()
self.assertFalse(lockable.locked())
示例7: test_refresh_locks_update_locks_to_current_time
# 需要导入模块: from plone.locking.interfaces import ILockable [as 别名]
# 或者: from plone.locking.interfaces.ILockable import lock [as 别名]
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)
示例8: begin
# 需要导入模块: from plone.locking.interfaces import ILockable [as 别名]
# 或者: from plone.locking.interfaces.ILockable import lock [as 别名]
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)
示例9: test_atct_not_lockable
# 需要导入模块: from plone.locking.interfaces import ILockable [as 别名]
# 或者: from plone.locking.interfaces.ILockable import lock [as 别名]
def test_atct_not_lockable(self):
portal = self.layer['portal']
setRoles(portal, TEST_USER_ID, ['Contributor'])
portal.invokeFactory('Document', 'adoc',
title='A title',
description='Some description',
text='Some text')
doc = portal['adoc']
lockable = ILockable(doc)
self.assertEqual(False, lockable.locked())
lockable.lock()
self.assertEqual(False, lockable.locked())
示例10: move_all_items_totarget
# 需要导入模块: from plone.locking.interfaces import ILockable [as 别名]
# 或者: from plone.locking.interfaces.ILockable import lock [as 别名]
def move_all_items_totarget(portal,sourcespace,targetspace,logger):
ct = getToolByName(portal,'portal_catalog')
logger.info("Moving items from %s to %s" % (sourcespace,targetspace,))
if sourcespace <> None:
#impersonate owner of the space
#print >> out, "impersonating owner of space: %s" % (sourcespace.Title(),)
#impersonateOwner(portal,sourcespace)
strPath = sourcespace.getPhysicalPath()
strURL = "/".join(strPath)
query = {'path': {'query': strURL},'portal_type':spacesdefaultaddablenonfolderishtypes}
objects = [b.getObject() for b in ct(query)]
logger.info("Moving %s items from space : %s" % (len(objects), sourcespace,))
for o in objects:
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()
parentobject = o.getParentNode()
cb = parentobject.manage_cutObjects(ids=[o_id])
targetspace.manage_pasteObjects(cb)
if was_locked:
lockable.lock()
transaction.savepoint()
except ComponentLookupError:
pass
#impersonateAdminUser(portal)
query1 = query = {'path': {'query': "/".join(targetspace.getPhysicalPath()),'depth':1},'portal_type':spacesdefaultaddablenonfolderishtypes}
movedobjects = ct(query1)
logger.info("Moved %s items to space : %s" % (len(movedobjects), targetspace,))
示例11: setId
# 需要导入模块: from plone.locking.interfaces import ILockable [as 别名]
# 或者: from plone.locking.interfaces.ILockable import lock [as 别名]
def setId(self, value):
"""Sets the object id.
"""
if value != self.getId():
parent = aq_parent(aq_inner(self))
if parent is not None:
# See Referenceable, keep refs on what is a move/rename
self._v_cp_refs = 1
# We can't rename if the object is locked
if HAS_LOCKING:
lockable = ILockable(self)
was_locked = False
if lockable.locked():
was_locked = True
lockable.unlock()
parent.manage_renameObject(self.id, value)
if was_locked:
lockable.lock()
else:
parent.manage_renameObject(self.id, value)
self._setId(value)
示例12: _set_id
# 需要导入模块: from plone.locking.interfaces import ILockable [as 别名]
# 或者: from plone.locking.interfaces.ILockable import lock [as 别名]
def _set_id(self, value):
if not value:
return
context = aq_inner(self.context)
parent = aq_parent(context)
if parent is None:
# Object hasn't been added to graph yet; just set directly
context.id = value
return
new_id = INameChooser(parent).chooseName(value, context)
if getattr(aq_base(context), 'id', None):
transaction.savepoint()
locked = False
lockable = ILockable(context, None)
if lockable is not None and lockable.locked():
locked = True
lockable.unlock()
parent.manage_renameObject(context.getId(), new_id)
if locked:
lockable.lock()
else:
context.id = new_id
示例13: setId
# 需要导入模块: from plone.locking.interfaces import ILockable [as 别名]
# 或者: from plone.locking.interfaces.ILockable import lock [as 别名]
def setId(self, value):
# Sets the object id.
# avoid CopyError in OFS.CopySupport.manage_renameObject(),
# see http://dev.plone.org/ticket/8338
value = value.strip()
if value != self.getId():
parent = aq_parent(aq_inner(self))
if parent is not None:
# See Referenceable, keep refs on what is a move/rename
self._v_cp_refs = 1
# We can't rename if the object is locked
if HAS_LOCKING:
lockable = ILockable(self)
was_locked = False
if lockable.locked():
was_locked = True
lockable.unlock()
parent.manage_renameObject(self.id, value)
if was_locked:
lockable.lock()
else:
parent.manage_renameObject(self.id, value)
self._setId(value)
示例14: replaceField
# 需要导入模块: from plone.locking.interfaces import ILockable [as 别名]
# 或者: from plone.locking.interfaces.ILockable import lock [as 别名]
def replaceField(self, fieldname, templateId, macro, uid=None, target=None, edit=False):
"""
kss commands to replace the field value by the edit widget
The edit parameter may be used if we are coming from something else
than an edit view.
"""
ksscore = self.getCommandSet('core')
zopecommands = self.getCommandSet('zope')
plonecommands = self.getCommandSet('plone')
instance = self._getFieldContext(uid)
if edit:
locking = ILockable(instance, 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 self.render()
else: # were are locking the content
locking.lock()
plonecommands.issuePortalMessage('')
html = self.renderEditField(fieldname, templateId, macro, uid)
html = html.strip()
field_id = target or "parent-fieldname-%s" % fieldname
ksscore.replaceHTML(ksscore.getHtmlIdSelector(field_id), html)
ksscore.focus("#%s .firstToFocus" % field_id)
return self.render()
示例15: test_lock_use_model_class_name_as_object_type
# 需要导入模块: from plone.locking.interfaces import ILockable [as 别名]
# 或者: from plone.locking.interfaces.ILockable import lock [as 别名]
def test_lock_use_model_class_name_as_object_type(self):
lockable = ILockable(self.wrapper)
lockable.lock()
lock = Lock.query.first()
self.assertEqual(u'Meeting', lock.object_type)