django-lifecycle icon indicating copy to clipboard operation
django-lifecycle copied to clipboard

Callables for is_now?

Open benwhalley opened this issue 5 years ago • 1 comments

I wonder if you'd considered allowing callable for is_now and was conditions? For example, if this function:

    def _check_is_now_condition(self, field_name: str, specs: dict) -> bool:
        return specs["is_now"] in (self._current_value(field_name), "*")

Was changed to something like:

    def _check_is_now_condition(self, field_name: str, specs: dict) -> bool:
        if callable(specs["is_now"]):
           return specs["is_now"](self)
        else:
           return specs["is_now"] in (self._current_value(field_name), "*")

Then users could pass a callable and implement any logic they like in relation to the tested values.

benwhalley avatar Aug 12 '20 11:08 benwhalley

That's interesting. I had not considered it. Is there a specific use case you're working on? Might be helpful for us to have something to work backward from.

rsinger86 avatar Aug 16 '20 21:08 rsinger86