﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
19636	inhibit signals to modify some field on tests	oscaracena@…	nobody	"A simple decorator to assure that the code in the decorated function does not send the signal inhibited.

The decorator may be something like the following:

{{{#!python
def inhibit_signal(signal, receiver, sender):
    def function_getter(fn):
        def decorator(*args, **kwargs):
            signal.disconnect(receiver=receiver, sender=sender)
            retval = fn(*args, **kwargs)
            signal.connect(receiver=receiver, sender=sender)
            return retval
        return decorator
    return function_getter
}}}

You could use it as this:

{{{#!python
# MyModel has a receiver connected on 'pre_save' signal, which updates its timestamp. 
# Yeah, I know it can be made with an auto_now field, but let it be for this example purposes :)
# Using this decorator, the function set_timestamp could make its work.

@inhibit_signal(signals.pre_save, on_mymodel_update_timestamp, MyModel)
def set_timestamp(object, ts):
    object.timestamp = ts
    object.save()
}}}"	New feature	closed	Testing framework	1.4	Normal	wontfix	signals, tests		Unreviewed	0	0	0	0	0	0
