本文整理汇总了Python中ZPublisher.BeforeTraverse类的典型用法代码示例。如果您正苦于以下问题:Python BeforeTraverse类的具体用法?Python BeforeTraverse怎么用?Python BeforeTraverse使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BeforeTraverse类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: manage_afterAdd
def manage_afterAdd(self, item, container):
if item is self:
container.__allow_groups__ = aq_base(self)
handle = self.meta_type + '/' + self.getId()
container = container.this()
nc = BeforeTraverse.NameCaller(self.getId())
BeforeTraverse.registerBeforeTraverse(container, nc, handle)
示例2: _cleanupBeforeTraverseHooks
def _cleanupBeforeTraverseHooks(self):
# unregister all before traversal hooks that do not belong to us.
my_handle = self.meta_type + '/' + self.getId()
handle_to_unregister_list = []
for (priority, handle), hook in self.__before_traverse__.items():
if isinstance(hook, self._getTraversalHookClass()) and handle != my_handle:
handle_to_unregister_list.append(handle)
for handle in handle_to_unregister_list:
BeforeTraverse.unregisterBeforeTraverse(self, handle)
示例3: manage_beforeDelete
def manage_beforeDelete(self, item, container):
if item is self:
try:
del container.__allow_groups__
except:
pass
handle = self.meta_type + '/' + self.getId()
BeforeTraverse.unregisterBeforeTraverse(container, handle)
示例4: manage_afterAdd
def manage_afterAdd(self, item, container):
if item is self:
id = self.id
if callable(id):
id = id()
# We want the original object, not stuff in between
container = container.this()
hook = BeforeTraverse.NameCaller(id)
BeforeTraverse.registerBeforeTraverse(container, hook, self.meta_type, self.priority)
示例5: _update
def _update(self, portal):
traversers = portal.__before_traverse__
for priority, name in traversers.keys():
if portal.getId() in name:
self.log.debug('Fix not needed')
return
name_caller = BeforeTraverse.NameCaller(portal.getId())
app_handle = '%s/%s' % (portal.meta_type, portal.getId())
BeforeTraverse.registerBeforeTraverse(portal, name_caller, app_handle)
self.log.debug('Fix applied!')
return True
示例6: _edit
def _edit(self, **kw):
# XXX it is unclear if we should keep this behavior in other potential subclasses.
# Probably yes.
if self.getPortalType() in ('Web Section', 'Web Site'):
if getattr(self, '__before_traverse__', None) is None:
# migrate beforeTraverse hook if missing
handle = self.meta_type + '/' + self.getId()
BeforeTraverse.registerBeforeTraverse(self, self._getTraversalHookClass()(), handle)
else:
# cleanup beforeTraverse hooks that may exist after this document was cloned.
self._cleanupBeforeTraverseHooks()
super(WebSection, self)._edit(**kw)
示例7: manage_afterAdd
def manage_afterAdd(self, item, container):
if item is self:
if BeforeTraverse.queryBeforeTraverse(container, self.meta_type):
raise BadRequest, ("This container already has a %s" % self.meta_type)
id = self.id
if callable(id):
id = id()
# We want the original object, not stuff in between
container = container.this()
hook = BeforeTraverse.NameCaller(id)
BeforeTraverse.registerBeforeTraverse(container, hook, self.meta_type, self.priority)
示例8: test_json_request_on_object_with_multihook
def test_json_request_on_object_with_multihook(self):
doc1 = self.portal[self.portal.invokeFactory('Document', id='doc1')]
# Register a function to be called before traversal
def btr_test(container, request):
request._btr_test_called = 1
doc1.btr_test = btr_test
nc = BeforeTraverse.NameCaller('btr_test')
BeforeTraverse.registerBeforeTraverse(doc1, nc, 'Document/btr_test')
obj = self.traverse(path='/plone/doc1')
self.assertTrue(isinstance(obj, Service), 'Not a service')
self.assertEquals(1, self.request._btr_test_called)
示例9: test_app_layer_enabled_directly
def test_app_layer_enabled_directly(self):
folder = api.content.create(container=self.portal,
type='Folder',
title='testfolder')
api.content.transition(folder, 'publish')
directlyProvides(folder, IMockFolder)
folder.app_layers = (IMockLayer,)
BeforeTraverse.registerBeforeTraverse(folder,
enable_app_layer(),
'enable_app_layer')
transaction.commit()
browser = Browser(self.app)
browser.open("%s/@@browser_layers" % folder.absolute_url())
self.assertTrue('ploneintranet.layout.tests.utils.IMockLayer'
in browser.contents)
示例10: movedNySite
def movedNySite(ob, event):
""" A NySite was moved """
if IObjectAddedEvent.providedBy(event):
#Hadled by addedNySite
return
elif IObjectRemovedEvent.providedBy(event):
#Hadled by removedNySite
return
else:
old_handle = ob.meta_type + '/' + event.oldName
BeforeTraverse.unregisterBeforeTraverse(ob, old_handle)
handle = ob.meta_type + '/' + event.newName
nc = BeforeTraverse.NameCaller(event.newName)
BeforeTraverse.registerBeforeTraverse(ob, nc, handle)
示例11: handleCookieCrumblerEvent
def handleCookieCrumblerEvent(ob, event):
""" Event subscriber for (un)registering a CC as a before traverse hook.
"""
if not ICookieCrumbler.providedBy(ob):
return
if IObjectMovedEvent.providedBy(event):
if event.newParent is not None:
# register before traverse hook
handle = ob.meta_type + '/' + ob.getId()
nc = BeforeTraverse.NameCaller(ob.getId())
BeforeTraverse.registerBeforeTraverse(event.newParent, nc, handle)
elif IObjectWillBeMovedEvent.providedBy(event):
if event.oldParent is not None:
# unregister before traverse hook
handle = ob.meta_type + '/' + ob.getId()
BeforeTraverse.unregisterBeforeTraverse(event.oldParent, handle)
示例12: manage_afterAdd
def manage_afterAdd(self, item, container):
""" after add event """
if item is self:
handle = self.meta_type + '/' + self.getId()
nc = BeforeTraverse.NameCaller(self.getId())
BeforeTraverse.registerBeforeTraverse(container, nc, handle)
self.loadDefaultRoles()
try:
self.createRepository()
style_css = open(join(DOCMANAGER_PRODUCT_PATH,'zpt','DocManager','DocManager_style.zpt'))
content = style_css.read()
style_css.close()
manage_addPageTemplate(self, id=DOCMANAGER_CSS, title='', text=content)
style_css = open(join(DOCMANAGER_PRODUCT_PATH,'zpt','DocManager','DocManager_template.zpt'))
content = style_css.read()
style_css.close()
manage_addPageTemplate(self, id=DOCMANAGER_TEMPLATE, title='', text=content)
Folder.inheritedAttribute('manage_afterAdd')(self, item, container)
except:
pass
示例13: manage_beforeDelete
def manage_beforeDelete(self, item, container):
if item is self:
BeforeTraverse.unregisterBeforeTraverse(container, self.meta_type)
示例14: manage_beforeDelete
def manage_beforeDelete(self, item, container):
if item is self:
handle = self.meta_type + '/' + self.getId()
BeforeTraverse.unregisterBeforeTraverse(container, handle)
示例15: _edit
def _edit(self, **kw):
# migrate beforeTraverse hook if missing
if getattr(self, '__before_traverse__', None) is None and self.getPortalType() == 'Web Section':
handle = self.meta_type + '/' + self.getId()
BeforeTraverse.registerBeforeTraverse(self, WebSectionTraversalHook(), handle)
super(WebSection, self)._edit(**kw)