本文整理汇总了Python中zope.container.interfaces.IContainerModifiedEvent类的典型用法代码示例。如果您正苦于以下问题:Python IContainerModifiedEvent类的具体用法?Python IContainerModifiedEvent怎么用?Python IContainerModifiedEvent使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了IContainerModifiedEvent类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testRenameEvents
def testRenameEvents(self):
self.assertRaises(KeyError, self.reflecto.manage_renameObjects,
('monty',), ('python',))
self.assertEqual(len(getEvents()), 0)
self.assertRaises(KeyError, self.reflecto.manage_renameObjects,
('foo', 'monty'), ('bar', 'python'))
self.assertEqual(len(getEvents()), 1)
events = getEvents(IObjectWillBeMovedEvent)
self.assertEqual(len(events), 1)
self.assertEqual(events[0].oldName, 'foo')
self.assertEqual(events[0].newName, 'bar')
self.assertEqual(self.reflecto.manage_renameObjects(('foo',), ('bar',)),
['foo'])
events = getEvents()
self.assertEqual(len(events), 4)
self.assertTrue(IObjectWillBeMovedEvent.providedBy(events[1]))
self.assertTrue(IObjectMovedEvent.providedBy(events[2]))
self.assertEqual(events[2].oldName, 'foo')
self.assertEqual(events[2].newName, 'bar')
self.assertTrue(IContainerModifiedEvent.providedBy(events[3]))
self.assertTrue(events[3].object is self.reflecto)
示例2: sync_task
def sync_task(obj, event):
"""Index the given task in opengever.globalindex.
"""
if IContainerModifiedEvent.providedBy(event):
return
TaskSqlSyncer(obj, event).sync()
示例3: test_events
def test_events(self):
from OFS.interfaces import IObjectWillBeAddedEvent
from zope.component import adapter
from zope.component import provideHandler
from zope.container.interfaces import IContainerModifiedEvent
from zope.container.interfaces import IObjectAddedEvent
from zope.lifecycleevent.interfaces import IObjectCreatedEvent
events = []
@adapter(IObjectCreatedEvent)
def _handleObjectCreated(event):
events.append(event)
provideHandler(_handleObjectCreated)
@adapter(IObjectWillBeAddedEvent)
def _handleObjectWillBeAdded(event):
events.append(event)
provideHandler(_handleObjectWillBeAdded)
@adapter(IObjectAddedEvent)
def _handleObjectAdded(event):
events.append(event)
provideHandler(_handleObjectAdded)
@adapter(IContainerModifiedEvent)
def _handleContainerModified(event):
events.append(event)
provideHandler(_handleContainerModified)
self.ti.constructInstance(self.f, 'foo')
self.assertEquals(len(events), 4)
evt = events[0]
self.failUnless(IObjectCreatedEvent.providedBy(evt))
self.assertEquals(evt.object, self.f.foo)
evt = events[1]
self.failUnless(IObjectWillBeAddedEvent.providedBy(evt))
self.assertEquals(evt.object, self.f.foo)
self.assertEquals(evt.oldParent, None)
self.assertEquals(evt.oldName, None)
self.assertEquals(evt.newParent, self.f)
self.assertEquals(evt.newName, 'foo')
evt = events[2]
self.failUnless(IObjectAddedEvent.providedBy(evt))
self.assertEquals(evt.object, self.f.foo)
self.assertEquals(evt.oldParent, None)
self.assertEquals(evt.oldName, None)
self.assertEquals(evt.newParent, self.f)
self.assertEquals(evt.newName, 'foo')
evt = events[3]
self.failUnless(IContainerModifiedEvent.providedBy(evt))
self.assertEquals(evt.object, self.f)
示例4: testCutEvents
def testCutEvents(self):
cp = self.reflecto.manage_cutObjects(('foo',))
self.reflecto['subdir'].manage_pasteObjects(cp)
events = getEvents()
self.assertEqual(len(events), 4)
self.assertTrue(IObjectWillBeMovedEvent.providedBy(events[0]))
self.assertEqual(events[0].oldName, 'foo')
self.assertEqual(events[0].oldParent, self.reflecto)
self.assertEqual(events[0].newName, 'foo')
self.assertEqual(events[0].newParent, self.reflecto['subdir'])
self.assertTrue(IObjectMovedEvent.providedBy(events[1]))
self.assertEqual(events[1].object.getId(), 'foo')
self.assertTrue(IContainerModifiedEvent.providedBy(events[2]))
self.assertEqual(events[2].object, self.reflecto)
self.assertTrue(IContainerModifiedEvent.providedBy(events[3]))
self.assertEqual(events[3].object, self.reflecto['subdir'])
示例5: propagate_vocab_restrictions_to_children
def propagate_vocab_restrictions_to_children(container, event):
if ILocalrolesModifiedEvent.providedBy(event) or \
IContainerModifiedEvent.providedBy(event):
return
restricted_fields = [
IClassification['classification'],
IClassification['privacy_layer']]
propagate_vocab_restrictions(
container, event, restricted_fields, IClassificationMarker)
示例6: index_and_update_author_modified_content
def index_and_update_author_modified_content(content, event):
"""A content have been created of modifed. Update its author
information.
"""
# In the same way, we discard event on versioned content if they
# are about adding or removing a version.
if IVersionedContent.providedBy(content) and IContainerModifiedEvent.providedBy(event):
return
if getattr(content, "__initialization__", False):
return
ChangesTask.get().modified(content)
ICataloging(content).reindex()
示例7: store_activity
def store_activity(document, event):
if IObjectInitializedEvent.providedBy(event):
return
elif IContainerModifiedEvent.providedBy(event):
return
elif not ILayer.providedBy(getattr(document, 'REQUEST', None)):
return
elif not IUUIDAware.providedBy(document):
return
folder = document.aq_parent
get_tool().store_activity(folder, 'modify', uid=IUUID(document))
示例8: set_roles_after_modifying
def set_roles_after_modifying(context, event):
# Handle the modify event having been a removal of a related item
setattr(
context,
'relatedItems',
[item for item in getattr(context, 'relatedItems', []) if item.to_object],
)
if IContainerModifiedEvent.providedBy(event):
return
LocalRolesSetter(context).set_roles(event)
示例9: propagate_vocab_restrictions_to_children
def propagate_vocab_restrictions_to_children(container, event):
if ILocalrolesModifiedEvent.providedBy(event) or \
IContainerModifiedEvent.providedBy(event):
return
restricted_fields = [
ILifeCycle['retention_period'],
ILifeCycle['archival_value'],
ILifeCycle['custody_period']]
propagate_vocab_restrictions(
container, event, restricted_fields, ILifeCycleMarker)
示例10: disposition_modified
def disposition_modified(context, event):
if IContainerModifiedEvent.providedBy(event):
return
# Skip modified events during dossier destruction
if IDuringDossierDestruction.providedBy(context.REQUEST):
return
storage = IHistoryStorage(context)
storage.add('edited',
api.user.get_current().getId(),
context.get_dossier_representations())
示例11: create_version_on_save
def create_version_on_save(context, event):
"""Creates a new version on a versionable object when the object is saved.
A new version is created if the type is automatic versionable and has
changed or if the user has entered a change note.
"""
# according to Products.CMFEditions' update_version_on_edit script
# only version the modified object, not its container on modification
if IContainerModifiedEvent.providedBy(event):
return
# XXX dirty hack for stagingbehavior, which triggers a event with
# a aq_based context when deleting the working copy
try:
pr = context.portal_repository
except AttributeError:
return
if not pr.isVersionable(context):
# cancel, the object is not versionable
return
create_version = False
if getattr(context, 'REQUEST', None):
changeNote = get_change_note(context.REQUEST, None)
else:
changeNote = None
if changeNote:
# user has entered a change note. create a new version even if nothing
# has changed.
create_version = True
elif pr.supportsPolicy(context, 'at_edit_autoversion'):
# automatic versioning is enabled for this portal type
if not base_hasattr(context, 'version_id'):
# we do not have a initial version
create_version = True
else:
try:
create_version = not pr.isUpToDate(context, context.version_id)
except ArchivistUnregisteredError:
# The object is not actually registered, but a version is
# set, perhaps it was imported, or versioning info was
# inappropriately destroyed
create_version = True
# create new version if needed
if create_version:
pr.save(obj=context, comment=changeNote)
示例12: update_reference_prefixes
def update_reference_prefixes(obj, event):
"""A eventhandler which reindex all contained objects, if the
reference prefix has been changed.
"""
if ILocalrolesModifiedEvent.providedBy(event) or \
IContainerModifiedEvent.providedBy(event):
return
if is_reference_number_prefix_changed(event.descriptions):
catalog = api.portal.get_tool('portal_catalog')
children = catalog.unrestrictedSearchResults(
path='/'.join(obj.getPhysicalPath()))
for child in children:
child.getObject().reindexObject(idxs=['reference'])
示例13: testCopyEvents
def testCopyEvents(self):
cp = self.reflecto.manage_copyObjects(('foo',))
self.reflecto.manage_pasteObjects(cp)
events = getEvents()
self.assertEqual(len(events), 3)
self.assertTrue(IObjectCopiedEvent.providedBy(events[0]))
self.assertEqual(events[0].original.getId(), 'foo')
self.assertEqual(events[0].object.getId(), 'copy_of_foo')
self.assertTrue(IObjectClonedEvent.providedBy(events[1]))
self.assertEqual(events[1].object.getId(), 'copy_of_foo')
self.assertTrue(IContainerModifiedEvent.providedBy(events[2]))
self.assertTrue(events[2].object is self.reflecto)
示例14: update_favorites_title
def update_favorites_title(context, event):
"""Event handler which updates the titles of all existing favorites for the
current context, unless the title is personalized.
"""
if IContainerModifiedEvent.providedBy(event):
return
if ILocalrolesModifiedEvent.providedBy(event):
return
if is_title_changed(event.descriptions):
query = Favorite.query.filter(
and_(Favorite.oguid == Oguid.for_object(context),
Favorite.is_title_personalized == False)) # noqa
query.update_title(context.title)
mark_changed(create_session())
示例15: saveReferenceNumberPrefix
def saveReferenceNumberPrefix(obj, event):
"""When an object providing IReferenceNumberPrefixMarker (repository
folders) gets added or has been modified, make sure it has
a unique reference number prefix.
If necessary, set_number() creates a collision free prefix.
"""
if IContainerModifiedEvent.providedBy(event):
return
parent = aq_parent(aq_inner(obj))
# Mark the reference number as issued in the parent's annotations
number = PrefixAdapter(parent).set_number(
obj, IReferenceNumberPrefix(obj).reference_number_prefix)
# Store the number on the actual object
IReferenceNumberPrefix(obj).reference_number_prefix = number