Question


I'm needing some help in the following situation: I need to implement a custom event/subscriber in order to be able to get the context of an object in the beginning and in the end of it's edition, because I need to compare the status of some fields of the object in both contexts.

Is there any way to do it? Is it possible to have a handler that is live/executes during all the editing process (it's beginning and the consolidation of the changes)? Maybe using threads?

Thanks in advance for any help!

Was it helpful?

Solution

Consider overriding your edit form to get what you want instead of trying to use subscribers here -- this might look like:

from plone.dexterity.browser.edit import DefaultEditForm as BaseForm

class ComparisonEditForm(BaseForm):

    def update(self, *args, **kwargs):
        existing_value = self.context.mykey
        BaseForm.update(self, *args, **kwargs)
        updated_value = self.context.mykey
        if existing_value != updated_value:
            pass # DO SOMETHING HERE

Then register an override in ZCML or something. YMMV, I have not tried this, but I think the general idea should work.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top