本文整理汇总了Python中plone.locking.interfaces.ILockable.can_safely_unlock方法的典型用法代码示例。如果您正苦于以下问题:Python ILockable.can_safely_unlock方法的具体用法?Python ILockable.can_safely_unlock怎么用?Python ILockable.can_safely_unlock使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类plone.locking.interfaces.ILockable
的用法示例。
在下文中一共展示了ILockable.can_safely_unlock方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: is_locked_by_another_user
# 需要导入模块: from plone.locking.interfaces import ILockable [as 别名]
# 或者: from plone.locking.interfaces.ILockable import can_safely_unlock [as 别名]
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()
示例2: safe_unlock
# 需要导入模块: from plone.locking.interfaces import ILockable [as 别名]
# 或者: from plone.locking.interfaces.ILockable import can_safely_unlock [as 别名]
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()
示例3: is_locked_for_current_user
# 需要导入模块: from plone.locking.interfaces import ILockable [as 别名]
# 或者: from plone.locking.interfaces.ILockable import can_safely_unlock [as 别名]
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()
示例4: is_available_for_current_user
# 需要导入模块: from plone.locking.interfaces import ILockable [as 别名]
# 或者: from plone.locking.interfaces.ILockable import can_safely_unlock [as 别名]
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()
示例5: begin
# 需要导入模块: from plone.locking.interfaces import ILockable [as 别名]
# 或者: from plone.locking.interfaces.ILockable import can_safely_unlock [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)
示例6: xmChangeWorkflowState
# 需要导入模块: from plone.locking.interfaces import ILockable [as 别名]
# 或者: from plone.locking.interfaces.ILockable import can_safely_unlock [as 别名]
def xmChangeWorkflowState(self, uid, url):
"""Change the workflow state, currently only of a Task."""
context = aq_inner(self.context)
ksscore = self.getCommandSet('core')
zopecommands = self.getCommandSet('zope')
plonecommands = self.getCommandSet('plone')
locking = ILockable(context, None)
if locking is not None and not locking.can_safely_unlock():
selector = ksscore.getHtmlIdSelector('plone-lock-status')
zopecommands.refreshViewlet(selector, 'plone.abovecontent',
'plone.lockinfo')
plonecommands.refreshContentMenu()
return self.render()
(proto, host, path, query, anchor) = urlsplit(url)
if not path.endswith('content_status_modify'):
raise KSSExplicitError('only content_status_modify is handled')
action = query.split("workflow_action=")[-1].split('&')[0]
uid_catalog = getToolByName(context, 'uid_catalog')
brain = uid_catalog(UID=uid)[0]
obj = brain.getObject()
# This may give a UnicodeDecodeError if the title has
# non-ascii characters:
# obj.content_status_modify(action)
# So we do it manually, which is better anyway:
wftool = getToolByName(context, 'portal_workflow')
wftool.doActionFor(obj, action=action)
if IXMStory.providedBy(self.context):
# Only refresh content if the context is a Story,
# otherwise you get too much tasks listed.
selector = ksscore.getCssSelector('.contentViews')
zopecommands.refreshViewlet(selector, 'plone.contentviews',
'plone.contentviews')
zopecommands.refreshProvider('.tasklist_table',
'xm.tasklist.simple')
plonecommands.refreshContentMenu()
else:
# In all other cases, we can at least refresh the part
# that shows the workflow info for this item.
wf_change = obj.restrictedTraverse('xm_workflow_change')
html = wf_change()
selector = ksscore.getHtmlIdSelector('id-%s' % uid)
ksscore.replaceHTML(selector, html)
self.issueAllPortalMessages()
self.cancelRedirect()
示例7: addTranslation
# 需要导入模块: from plone.locking.interfaces import ILockable [as 别名]
# 或者: from plone.locking.interfaces.ILockable import can_safely_unlock [as 别名]
def addTranslation(self, language, *args, **kwargs):
"""Adds a translation."""
canonical = self.getCanonical()
parent = aq_parent(aq_inner(self))
if ITranslatable.providedBy(parent):
parent = parent.getTranslation(language) or parent
if self.hasTranslation(language):
translation = self.getTranslation(language)
raise AlreadyTranslated, translation.absolute_url()
id = canonical.getId()
while not parent.checkIdAvailable(id):
id = '%s-%s' % (id, language)
kwargs[config.KWARGS_TRANSLATION_KEY] = canonical
if kwargs.get('language', None) != language:
kwargs['language'] = language
o = _createObjectByType(self.portal_type, parent, id, *args, **kwargs)
# If there is a custom factory method that doesn't add the
# translation relationship, make sure it is done now.
if o.getCanonical() != canonical:
o.addTranslationReference(canonical)
self.invalidateTranslationCache()
# Copy over the language independent fields
schema = canonical.Schema()
independent_fields = schema.filterFields(languageIndependent=True)
for field in independent_fields:
accessor = field.getEditAccessor(canonical)
if not accessor:
accessor = field.getAccessor(canonical)
data = accessor()
translation_mutator = getattr(o, field.translation_mutator)
translation_mutator(data)
# If this is a folder, move translated subobjects aswell.
if self.isPrincipiaFolderish:
moveids = []
for obj in self.objectValues():
if ITranslatable.providedBy(obj) and \
obj.getLanguage() == language:
lockable = ILockable(obj, None)
if lockable is not None and lockable.can_safely_unlock():
lockable.unlock()
moveids.append(obj.getId())
if moveids:
o.manage_pasteObjects(self.manage_cutObjects(moveids))
o.reindexObject()
if isDefaultPage(canonical, self.REQUEST):
o._lp_default_page = True
示例8: replaceWithView
# 需要导入模块: from plone.locking.interfaces import ILockable [as 别名]
# 或者: from plone.locking.interfaces.ILockable import can_safely_unlock [as 别名]
def replaceWithView(self, fieldname, templateId, macro, uid=None, target=None, edit=False):
"""
kss commands to replace the edit widget by the field view
"""
ksscore = self.getCommandSet('core')
instance = self._getFieldContext(uid)
locking = ILockable(instance, None)
if locking and locking.can_safely_unlock():
locking.unlock()
html = self.renderViewField(fieldname, templateId, macro, uid)
html = html.strip()
field_id = target or "parent-fieldname-%s" % fieldname
ksscore.replaceHTML(ksscore.getHtmlIdSelector(field_id), html)
return self.render()
示例9: cancel
# 需要导入模块: from plone.locking.interfaces import ILockable [as 别名]
# 或者: from plone.locking.interfaces.ILockable import can_safely_unlock [as 别名]
def cancel(self, fieldname):
"""Cancel the inline editing taking place for the given field, by
removing the inline editing form and unhiding the block with id
'${fieldname}-display'.
"""
context = aq_inner(self.context)
display_id = '%s-display' % fieldname
form_id = '%s-form' % fieldname
ksscore = self.getCommandSet('core')
# unlock the context if it was locked before
locking = ILockable(context, None)
if locking and locking.can_safely_unlock():
locking.unlock()
# show the existing display field
ksscore.removeClass(ksscore.getHtmlIdSelector(display_id), 'hiddenStructure')
# hide the form
ksscore.deleteNode(ksscore.getHtmlIdSelector(form_id))
示例10: changeWorkflowState
# 需要导入模块: from plone.locking.interfaces import ILockable [as 别名]
# 或者: from plone.locking.interfaces.ILockable import can_safely_unlock [as 别名]
def changeWorkflowState(self, url):
context = aq_inner(self.context)
ksscore = self.getCommandSet('core')
zopecommands = self.getCommandSet('zope')
plonecommands = self.getCommandSet('plone')
locking = ILockable(context, None)
if locking is not None and not locking.can_safely_unlock():
selector = ksscore.getHtmlIdSelector('plone-lock-status')
zopecommands.refreshViewlet(selector, 'plone.abovecontent', 'plone.lockinfo')
plonecommands.refreshContentMenu()
return self.render()
(proto, host, path, query, anchor) = urlsplit(url)
if not path.endswith('content_status_modify'):
raise KSSExplicitError, 'content_status_modify is not handled'
action = query.split("workflow_action=")[-1].split('&')[0]
context.content_status_modify(action)
selector = ksscore.getCssSelector('.contentViews')
zopecommands.refreshViewlet(selector, 'plone.contentviews', 'plone.contentviews')
plonecommands.refreshContentMenu()
self.issueAllPortalMessages()
self.cancelRedirect()
示例11: replaceField
# 需要导入模块: from plone.locking.interfaces import ILockable [as 别名]
# 或者: from plone.locking.interfaces.ILockable import can_safely_unlock [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()
示例12: createTranslation
# 需要导入模块: from plone.locking.interfaces import ILockable [as 别名]
# 或者: from plone.locking.interfaces.ILockable import can_safely_unlock [as 别名]
def createTranslation(self, container, language, *args, **kwargs):
context = aq_inner(self.context)
canonical = context.getCanonical()
portal_type = self.getTranslationPortalType(container, language)
new_id = kwargs.pop(
'id', self.generateId(container, canonical.getId(), language))
kwargs["language"] = language
translation = _createObjectByType(portal_type, container,
new_id, *args, **kwargs)
# If there is a custom factory method that doesn't add the
# translation relationship, make sure it is done now.
if translation.getCanonical() != canonical:
translation.addTranslationReference(canonical)
# THIS IS THE LINE WE NEED TO CUSTOMIZE
OSHALanguageIndependentFields(canonical).copyFields(translation)
if isDefaultPage(aq_parent(aq_inner(canonical)), canonical):
translation._lp_default_page = True
# If this is a folder, move translated subobjects aswell.
if context.isPrincipiaFolderish:
moveids = []
for obj in context.values():
translator = ITranslatable(obj, None)
if translator is not None \
and translator.getLanguage() == language:
lockable = ILockable(obj, None)
if lockable is not None and lockable.can_safely_unlock():
lockable.unlock()
moveids.append(obj.getId())
if moveids:
info = context.manage_cutObjects(moveids)
translation.manage_pasteObjects(info)
return translation
示例13: safe_unlock
# 需要导入模块: from plone.locking.interfaces import ILockable [as 别名]
# 或者: from plone.locking.interfaces.ILockable import can_safely_unlock [as 别名]
def safe_unlock(self):
"""Unlock the object if the current user has the lock
"""
lockable = ILockable(self.context)
if lockable.can_safely_unlock():
lockable.unlock()
示例14: test_can_safely_unlock_is_true_if_no_lock_exists
# 需要导入模块: from plone.locking.interfaces import ILockable [as 别名]
# 或者: from plone.locking.interfaces.ILockable import can_safely_unlock [as 别名]
def test_can_safely_unlock_is_true_if_no_lock_exists(self):
lockable = ILockable(self.wrapper)
self.assertTrue(lockable.can_safely_unlock())
示例15: unlockAfterModification
# 需要导入模块: from plone.locking.interfaces import ILockable [as 别名]
# 或者: from plone.locking.interfaces.ILockable import can_safely_unlock [as 别名]
def unlockAfterModification(obj, event):
"""Release the DAV lock after save
"""
lockable = ILockable(obj)
if lockable.can_safely_unlock():
lockable.unlock()