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:
parent
94d90efad5
commit
dc9928f316
2 changed files with 4 additions and 16 deletions
|
@ -28,11 +28,7 @@ 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, created: bool, **kwargs):
|
def create_user_no_responses(instance: User, **kwargs):
|
||||||
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
|
# 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)
|
||||||
|
@ -43,5 +39,7 @@ def create_user_no_responses(instance: User, created: bool, **kwargs):
|
||||||
status=RaidResponse.NO_RESPONSE,
|
status=RaidResponse.NO_RESPONSE,
|
||||||
attendance=RaidResponse.STATUS_DEFAULT_ATTENDANCE[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)
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
|
@ -48,14 +48,6 @@ 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"):
|
||||||
|
@ -83,8 +75,6 @@ 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