Only create no-responses if user did something that warrants it.
This commit is contained in:
parent
bb16c152c4
commit
94d90efad5
|
@ -28,8 +28,12 @@ def create_raid_no_responses(instance: Raid, **kwargs):
|
||||||
|
|
||||||
|
|
||||||
@receiver(post_save, sender=User)
|
@receiver(post_save, sender=User)
|
||||||
def create_user_no_responses(instance: User, **kwargs):
|
def create_user_no_responses(instance: User, created: bool, **kwargs):
|
||||||
# Delete all pre-existing no-responses for this user, in case date_joined or main as changed
|
if (instance.original_main_id, instance.original_date_joined) == (instance.main_id, instance.date_joined) \
|
||||||
|
and not created:
|
||||||
|
return
|
||||||
|
|
||||||
|
# Delete all pre-existing no-responses for this user, in case date_joined or main was changed
|
||||||
RaidResponse.objects.filter(character__user=instance, status=RaidResponse.NO_RESPONSE).delete()
|
RaidResponse.objects.filter(character__user=instance, status=RaidResponse.NO_RESPONSE).delete()
|
||||||
# Then create them (again)
|
# Then create them (again)
|
||||||
RaidResponse.objects.bulk_create(
|
RaidResponse.objects.bulk_create(
|
||||||
|
|
|
@ -48,6 +48,14 @@ class User(AbstractUser):
|
||||||
class Meta:
|
class Meta:
|
||||||
ordering = ["rank", "username"]
|
ordering = ["rank", "username"]
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
super().__init__(*args, **kwargs)
|
||||||
|
self._set_originals()
|
||||||
|
|
||||||
|
def _set_originals(self):
|
||||||
|
self.original_main_id = self.main_id
|
||||||
|
self.original_date_joined = self.date_joined
|
||||||
|
|
||||||
def clean(self):
|
def clean(self):
|
||||||
self.username = self.normalize_username(self.username)
|
self.username = self.normalize_username(self.username)
|
||||||
if not hasattr(self, "rank"):
|
if not hasattr(self, "rank"):
|
||||||
|
@ -75,6 +83,8 @@ class User(AbstractUser):
|
||||||
user = super().save(*args, **kwargs)
|
user = super().save(*args, **kwargs)
|
||||||
self.main.user = self
|
self.main.user = self
|
||||||
self.main.save()
|
self.main.save()
|
||||||
|
|
||||||
|
self._set_originals()
|
||||||
return user
|
return user
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue