allow suppressing of ObjectModifiedEvent (if done later by caller)

This commit is contained in:
Helmut Merz 2019-04-26 10:33:33 +02:00
parent 233d146587
commit e1b1a82ee1

View file

@ -1,5 +1,5 @@
# #
# Copyright (c) 2011 Helmut Merz helmutm@cy55.de # Copyright (c) 2019 Helmut Merz helmutm@cy55.de
# #
# This program is free software; you can redistribute it and/or modify # This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@ -260,7 +260,7 @@ class SetupManager(object):
return addAndConfigureObject(container, class_, name, **kw) return addAndConfigureObject(container, class_, name, **kw)
def addObject(container, class_, name, **kw): def addObject(container, class_, name, notifyModified=True, **kw):
created = False created = False
if name in container: if name in container:
obj = container[name] obj = container[name]
@ -275,14 +275,15 @@ def addObject(container, class_, name, **kw):
setattr(obj, attr, value) setattr(obj, attr, value)
if created: if created:
notify(ObjectCreatedEvent(obj)) notify(ObjectCreatedEvent(obj))
if notifyModified:
notify(ObjectModifiedEvent(obj)) notify(ObjectModifiedEvent(obj))
return obj return obj
def addAndConfigureObject(container, class_, name, **kw): def addAndConfigureObject(container, class_, name, notifyModified=True, **kw):
basicAttributes = ('title', 'description', 'conceptType', 'resourceType', basicAttributes = ('title', 'description', 'conceptType', 'resourceType',
'nodeType', 'body') 'nodeType', 'body')
basicKw = dict([(k, kw[k]) for k in kw if k in basicAttributes]) basicKw = dict([(k, kw[k]) for k in kw if k in basicAttributes])
obj = addObject(container, class_, name, **basicKw) obj = addObject(container, class_, name, notifyModified=False, **basicKw)
adapted = obj adapted = obj
if class_ in (Concept, Resource): if class_ in (Concept, Resource):
ti = IType(obj).typeInterface ti = IType(obj).typeInterface
@ -291,6 +292,7 @@ def addAndConfigureObject(container, class_, name, **kw):
adapterAttributes = [k for k in kw if k not in basicAttributes] adapterAttributes = [k for k in kw if k not in basicAttributes]
for attr in adapterAttributes: for attr in adapterAttributes:
setattr(adapted, attr, kw[attr]) setattr(adapted, attr, kw[attr])
if notifyModified:
notify(ObjectModifiedEvent(obj)) notify(ObjectModifiedEvent(obj))
return obj return obj