Fix bug causing automatic attendance to not be updated when user first signs up then off.
This commit is contained in:
parent
0ac3bda6b7
commit
5ea6e75d0a
18
drakul/raids/migrations/0003_auto_20191119_0412.py
Normal file
18
drakul/raids/migrations/0003_auto_20191119_0412.py
Normal file
|
@ -0,0 +1,18 @@
|
|||
# Generated by Django 2.2.6 on 2019-11-19 04:12
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('raids', '0002_auto_20191119_0310'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='raidresponse',
|
||||
name='status',
|
||||
field=models.PositiveSmallIntegerField(choices=[(1, 'Signed Off'), (2, 'Signed Up'), (3, 'Stand By'), (4, 'Confirmed')]),
|
||||
),
|
||||
]
|
|
@ -70,8 +70,7 @@ class RaidResponse(models.Model):
|
|||
(SIGNED_UP, "Signed Up"),
|
||||
]
|
||||
status = models.PositiveSmallIntegerField(
|
||||
choices=STATUS_CHOICES,
|
||||
default=SIGNED_UP
|
||||
choices=STATUS_CHOICES
|
||||
)
|
||||
|
||||
note = models.CharField(
|
||||
|
@ -92,6 +91,10 @@ class RaidResponse(models.Model):
|
|||
models.UniqueConstraint(fields=["raid", "character"], name="unique_character_raid_signup")
|
||||
]
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self._original_status = self.status
|
||||
|
||||
def clean(self):
|
||||
# Make sure sign-offs are role-agnostic, but all other responses are not
|
||||
if self.status == RaidResponse.SIGNED_OFF:
|
||||
|
@ -99,14 +102,16 @@ class RaidResponse(models.Model):
|
|||
elif self.role is None:
|
||||
raise ValidationError({"role": "This field is required."})
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
# Set attendance if it hasn't been set manually
|
||||
if self.attendance is None:
|
||||
# Set attendance to one of the default values if status was changed
|
||||
if self.status != self._original_status:
|
||||
if self.status >= RaidResponse.SIGNED_UP:
|
||||
self.attendance = settings.DEFAULT_ATTENDANCE_ATTENDING # 1.0 by default
|
||||
else:
|
||||
self.attendance = settings.DEFAULT_ATTENDANCE_NOT_ATTENDING # 0.0 by default
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
super().save(*args, **kwargs)
|
||||
self._original_status = self.status
|
||||
|
||||
def __str__(self):
|
||||
return super().__str__() # TODO?
|
||||
|
|
Loading…
Reference in a new issue