From 4577855d60fcccbb199d19cc3d02b050a6917711 Mon Sep 17 00:00:00 2001 From: Gaetan Delannay Date: Fri, 17 Oct 2014 11:22:49 +0200 Subject: [PATCH] [gen] Added a new hook in the object creation algorithm: 'onEditEarly', called before an object being created is linked to its initiator object. Indeed, 'onEdit' is called after the link has been done, and sometimes, the linking may need some information that must be set before calling onEdit, thus via this new method onEditEarly. --- gen/mixins/__init__.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/gen/mixins/__init__.py b/gen/mixins/__init__.py index 1360e2a..24d2e44 100644 --- a/gen/mixins/__init__.py +++ b/gen/mixins/__init__.py @@ -97,16 +97,20 @@ class BaseMixin: # Keep in history potential changes on historized fields obj.historizeData(previousData) + # Call the custom "onEditEarly" if available. This method is called + # *before* potentially linking the object to its initiator. + appyObject = obj.appy() + if created and hasattr(appyObject, 'onEditEarly'): + appyObject.onEditEarly() + # Manage potential link with an initiator object if created and initiator: - initiator.appy().link(initiatorField.name, obj.appy()) + initiator.appy().link(initiatorField.name, appyObject) # Call the custom "onEdit" if available msg = None # The message to display to the user. It can be set by onEdit - if obj.wrapperClass: - appyObject = obj.appy() - if hasattr(appyObject, 'onEdit'): - msg = appyObject.onEdit(created) + if hasattr(appyObject, 'onEdit'): msg = appyObject.onEdit(created) + # Update last modification date if not created: from DateTime import DateTime