本文整理汇总了Python中plone.locking.interfaces.ILockable.unlock方法的典型用法代码示例。如果您正苦于以下问题:Python ILockable.unlock方法的具体用法?Python ILockable.unlock怎么用?Python ILockable.unlock使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类plone.locking.interfaces.ILockable
的用法示例。
在下文中一共展示了ILockable.unlock方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: remove_spacesobject_fromsite
# 需要导入模块: from plone.locking.interfaces import ILockable [as 别名]
# 或者: from plone.locking.interfaces.ILockable import unlock [as 别名]
def remove_spacesobject_fromsite(portal,logger):
from plone.app.linkintegrity.interfaces import ILinkIntegrityNotificationException
portal_properties=getToolByName(portal, 'portal_properties')
is_link_integrity = portal_properties.site_properties.enable_link_integrity_checks
if is_link_integrity:
portal_properties.site_properties.manage_changeProperties(enable_link_integrity_checks=False)
spaces = None
try:
spaces = getToolByName(portal,'spaces')
if spaces.portal_type != 'SpacesFolder':
spaces = None
except AttributeError:
pass
spacesid = 'spaces'
try:
if spaces <> None:
if callable(spaces.id):
o_id = spaces.id()
else:
o_id = spaces.id
spacesid = o_id
from plone.locking.interfaces import ILockable
lockable = ILockable(spaces)
was_locked = False
if lockable.locked():
was_locked = True
lockable.unlock()
portal.manage_delObjects(ids=[o_id])
logger.info("Deleted spaces object from site.")
transaction.savepoint()
except ILinkIntegrityNotificationException:
pass
recyclebin = getToolByName(portal,'recyclebin')
if recyclebin <> None:
try:
objspaces = getattr(portal,spacesid)
if objspaces.portal_type == 'SpacesFolder':
from plone.locking.interfaces import ILockable
lockable = ILockable(objspaces)
was_locked = False
if lockable.locked():
was_locked = True
lockable.unlock()
recyclebin.manage_delObjects(ids=[spacesid])
logger.info("Deleting spaces object from global recyclebin.")
except AttributeError:
pass
if is_link_integrity:
portal_properties.site_properties.manage_changeProperties(enable_link_integrity_checks=True)
示例2: delete_unwanted_objects_from_memberfolder
# 需要导入模块: from plone.locking.interfaces import ILockable [as 别名]
# 或者: from plone.locking.interfaces.ILockable import unlock [as 别名]
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()
示例3: safe_unlock
# 需要导入模块: from plone.locking.interfaces import ILockable [as 别名]
# 或者: from plone.locking.interfaces.ILockable import 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()
示例4: force_unlock
# 需要导入模块: from plone.locking.interfaces import ILockable [as 别名]
# 或者: from plone.locking.interfaces.ILockable import unlock [as 别名]
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()
示例5: 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 unlock [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())
示例6: step1andstep2
# 需要导入模块: from plone.locking.interfaces import ILockable [as 别名]
# 或者: from plone.locking.interfaces.ILockable import unlock [as 别名]
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
示例7: unlockPerson
# 需要导入模块: from plone.locking.interfaces import ILockable [as 别名]
# 或者: from plone.locking.interfaces.ILockable import unlock [as 别名]
def unlockPerson(self):
obj = self.context.aq_inner
try:
from plone.locking.interfaces import ILockable
HAS_LOCKING = True
except ImportError:
HAS_LOCKING = False
if HAS_LOCKING:
lockable = ILockable(obj)
if lockable.locked():
lockable.unlock()
return self.render()
示例8: step3
# 需要导入模块: from plone.locking.interfaces import ILockable [as 别名]
# 或者: from plone.locking.interfaces.ILockable import unlock [as 别名]
def step3(self):
"""Move the existing site content to its correspondent RLF.
"""
portal = getSite()
pc = getToolByName(portal, "portal_catalog")
pl = getToolByName(portal, "portal_languages")
supported_langs = pl.getSupportedLanguages()
output = []
# Step 3: Move all the remaining content to its correspondent RLFs
for lang in supported_langs:
RLF_id = "%s" % lang
folder = getattr(portal, RLF_id, None)
if not folder:
raise AttributeError("One of the root language folder are \
missing. Check the site's language \
setup.")
path = '/'.join(portal.getPhysicalPath())
objects = pc.searchResults(path={'query': path, 'depth': 1},
sort_on='getObjPositionInParent',
Language=lang)
for brain in objects:
if brain.id != lang:
old_path = brain.getPath()
try:
cutted = self.context.manage_cutObjects(brain.id)
except ResourceLockedError:
content = brain.getObject()
lockable = ILockable(content)
lockable.unlock()
cutted = self.context.manage_cutObjects(brain.id)
try:
folder.manage_pasteObjects(cutted)
info_str = "Moved object %s to language root folder "\
"%s" % (old_path, lang)
log = logger.info
except Exception as err:
info_str = "ERROR. Step 3: not possible to move "\
"object %s to root language folder %s. Error: %s"\
% (old_path, lang, err)
log = logger.error
log(info_str)
output.append(info_str)
logger.info('Finished step 3')
return output
示例9: move_all_items_totarget
# 需要导入模块: from plone.locking.interfaces import ILockable [as 别名]
# 或者: from plone.locking.interfaces.ILockable import unlock [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,))
示例10: addTranslation
# 需要导入模块: from plone.locking.interfaces import ILockable [as 别名]
# 或者: from plone.locking.interfaces.ILockable import 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
示例11: force_unlock
# 需要导入模块: from plone.locking.interfaces import ILockable [as 别名]
# 或者: from plone.locking.interfaces.ILockable import unlock [as 别名]
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:
url = self.context.absolute_url()
props_tool = getToolByName(self.context, 'portal_properties')
if props_tool:
types_use_view = props_tool.site_properties.typesUseViewActionInListings
if self.context.portal_type in types_use_view:
url += '/view'
self.request.RESPONSE.redirect(url)
示例12: kss_obj_delete
# 需要导入模块: from plone.locking.interfaces import ILockable [as 别名]
# 或者: from plone.locking.interfaces.ILockable import unlock [as 别名]
def kss_obj_delete(self, selector='.kssDeletionRegion'):
obj = self.context.aq_inner
if obj.getPortalTypeName() == 'Discussion Item':
parent = obj.inReplyTo()
if parent is not None:
portal_discussion = getUtility(IDiscussionTool)
talkback = portal_discussion.getDiscussionFor(parent)
else:
talkback = obj.aq_parent
# remove the discussion item
talkback.deleteReply( str(obj.getId()) )
else:
# 被锁定时先解锁
if HAS_LOCKING:
lockable = ILockable(obj)
if lockable.locked():
lockable.unlock()
parent = obj.aq_parent
# archetypes的manage_delObjects会检查每个item的删除权限
originalSecurityManager = SecurityManagement.getSecurityManager()
SecurityManagement.newSecurityManager(None, User.SimpleUser('admin','',('Manager',), ''))
parent.manage_delObjects(str(obj.getId()))
SecurityManagement.setSecurityManager(originalSecurityManager)
if selector.startswith('redirect2'):
# 跳转到某个地址
# 需要定义 # class="kssattr-delSelector-redirect2http://test.everydo.com"
redirect2url = selector[len('redirect2'):]
self.getCommandSet('zopen').redirect(url=redirect2url)
else:
core = self.getCommandSet('core')
effects = self.getCommandSet('effects')
selector = core.getParentNodeSelector(selector)
# effects.effect(selector, 'fade')
core.deleteNode(selector)
self.getCommandSet('plone').issuePortalMessage(
translate(_(u'Deleted.'), default="Deleted.", context=self.request),
translate(_(u'Info'), default="Info", context=self.request))
return self.render()
示例13: replaceWithView
# 需要导入模块: from plone.locking.interfaces import ILockable [as 别名]
# 或者: from plone.locking.interfaces.ILockable import 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()
示例14: move_project_advisory
# 需要导入模块: from plone.locking.interfaces import ILockable [as 别名]
# 或者: from plone.locking.interfaces.ILockable import unlock [as 别名]
def move_project_advisory(obj, event=None):
"""Move advisory to other theme if project changes its theme.
This event is called everytime an object with a theme is updated.
After the initial migration to the new theme folders, some projects
will need to be linked to a different theme. When an advisory is
linked to this project, the theme of the advisory must be updated as
well. This means we need to move the advisory to a different theme
folder.
"""
# Be defensive in case we are called on an object that is not a Project.
advisory_getter = getattr(obj, 'get_public_advisory', None)
if advisory_getter is None:
return
advisory = advisory_getter()
if advisory is None:
return
project_theme = obj.getThemeTitle()
advisory_theme = advisory.getThemeTitle()
if project_theme == advisory_theme:
return
target = obj.getThemeObject()
lockable = ILockable(advisory)
if lockable.locked():
# During migration, we always want to unlock. During daily use, we
# want to be a bit more careful.
if event is not None:
lock_info = lockable.lock_info()[0]
lock_age = time.time() - lock_info.get('time', 0)
if lock_age < (5 * 60):
IStatusMessage(obj.REQUEST).addStatusMessage(
u'Gelinkt advies kon niet verplaatst worden naar nieuw '
u'thema: het wordt nu bewerkt door %s.' %
lock_info.get('creator'),
type='warning')
return
lockable.unlock()
logger.info("Unlocked advisory %s", advisory.title)
logger.info("Moving advisory %s from %r to %r",
advisory.title, advisory_theme, project_theme)
api.content.move(source=advisory, target=target)
示例15: setId
# 需要导入模块: from plone.locking.interfaces import ILockable [as 别名]
# 或者: from plone.locking.interfaces.ILockable import unlock [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)