Remove logic for checking if create_user_no_responses is required; just do it on all user save's instead to avoid edge-cases.

This commit is contained in:
Casper V. Kristensen 2020-01-07 02:32:01 +01:00
parent 94d90efad5
commit dc9928f316
Signed by: caspervk
GPG key ID: 289CA03790535054
2 changed files with 4 additions and 16 deletions

View file

@ -28,11 +28,7 @@ def create_raid_no_responses(instance: Raid, **kwargs):
@receiver(post_save, sender=User)
def create_user_no_responses(instance: User, created: bool, **kwargs):
if (instance.original_main_id, instance.original_date_joined) == (instance.main_id, instance.date_joined) \
and not created:
return
def create_user_no_responses(instance: User, **kwargs):
# 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()
# Then create them (again)
@ -43,5 +39,7 @@ def create_user_no_responses(instance: User, created: bool, **kwargs):
status=RaidResponse.NO_RESPONSE,
attendance=RaidResponse.STATUS_DEFAULT_ATTENDANCE[RaidResponse.NO_RESPONSE]
)
for raid in Raid.objects.filter(response_deadline__gte=instance.date_joined)
for raid in Raid.objects.exclude(
Q(response_deadline__lt=instance.date_joined) | Q(responses__character__user=instance)
)
)

View file

@ -48,14 +48,6 @@ class User(AbstractUser):
class Meta:
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):
self.username = self.normalize_username(self.username)
if not hasattr(self, "rank"):
@ -83,8 +75,6 @@ class User(AbstractUser):
user = super().save(*args, **kwargs)
self.main.user = self
self.main.save()
self._set_originals()
return user