Skip to content

Commit

Permalink
previous_values_are_unequal
Browse files Browse the repository at this point in the history
  • Loading branch information
SKairinos committed Jun 21, 2024
1 parent 1e961b2 commit b00d7de
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion codeforlife/models/signals/post_save.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def check_previous_values(
):
# pylint: disable=line-too-long
"""Check if the previous values are as expected. If the previous value's key
is not on the model, this check returns false.
is not on the model, this check returns False.
Args:
instance: The current instance.
Expand All @@ -42,6 +42,31 @@ def check_previous_values(
return True


def previous_values_are_unequal(instance: _.AnyModel, fields: t.Set[str]):
# pylint: disable=line-too-long
"""Check if all the previous values are not equal to the current values. If
the previous value's key is not on the model, this check returns False.
Args:
instance: The current instance.
fields: The fields that should not be equal.
Returns:
If all the previous values are not equal to the current values.
"""
# pylint: enable=line-too-long

for field in fields:
previous_value_key = PREVIOUS_VALUE_KEY.format(field=field)

if not hasattr(instance, previous_value_key) or (
getattr(instance, field) == getattr(instance, previous_value_key)
):
return False

return True


def get_previous_value(
instance: _.AnyModel, field: str, cls: t.Type[FieldValue]
):
Expand Down

0 comments on commit b00d7de

Please sign in to comment.