diff --git a/mailauth/contrib/user/models.py b/mailauth/contrib/user/models.py index fc310c4..0574c2c 100644 --- a/mailauth/contrib/user/models.py +++ b/mailauth/contrib/user/models.py @@ -113,15 +113,13 @@ def anonymize(self, commit=True): if commit: self.save() """ + signals.anonymize.send(sender=self.__class__, instance=self) self.email = None self.first_name = "" self.last_name = "" update_fields = ["email", "first_name", "last_name"] if commit: self.save(update_fields=update_fields) - signals.anonymize.send( - sender=self.__class__, instance=self, update_fields=tuple(update_fields) - ) return update_fields diff --git a/mailauth/contrib/user/signals.py b/mailauth/contrib/user/signals.py index 3bfa2a1..0a562b3 100644 --- a/mailauth/contrib/user/signals.py +++ b/mailauth/contrib/user/signals.py @@ -4,6 +4,11 @@ """ Signal that is emitted when a user and all their data should be anonymized. +The signal is emitted before the private date is delete on the instance, +thus the receiver can still access the data. The receiver should usually +not alter the instance, but only later related data. We recommend overriding +the anonymize method to modify the instance. + Usage:: from django.dispatch import receiver @@ -12,7 +17,7 @@ @receiver(anonymize, sender=EmailUser) - def anonymize_user(sender, instance, update_fields, **kwargs): + def anonymize_user(sender, instance, **kwargs): # Do something with related user data instance.related_model.delete() diff --git a/tests/contrib/auth/test_signals.py b/tests/contrib/auth/test_signals.py index ef8c280..f2ec392 100644 --- a/tests/contrib/auth/test_signals.py +++ b/tests/contrib/auth/test_signals.py @@ -16,5 +16,4 @@ def test_anonymize(user): signal=anonymize, sender=user.__class__, instance=user, - update_fields=("email", "first_name", "last_name"), )