Compare commits

..

2 commits

3 changed files with 31 additions and 10 deletions

View 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')]),
),
]

View file

@ -26,10 +26,9 @@ class Raid(models.Model):
class Meta: class Meta:
ordering = ["-date"] ordering = ["-date"]
def save(self, *args, **kwargs): def clean(self):
if self.response_deadline is None: if self.response_deadline is None:
self.response_deadline = self.date - timedelta(hours=24) self.response_deadline = self.date - timedelta(hours=24)
return super().save(*args, **kwargs)
def __str__(self): def __str__(self):
return f"{self.title} on {self.date}" return f"{self.title} on {self.date}"
@ -71,8 +70,7 @@ class RaidResponse(models.Model):
(SIGNED_UP, "Signed Up"), (SIGNED_UP, "Signed Up"),
] ]
status = models.PositiveSmallIntegerField( status = models.PositiveSmallIntegerField(
choices=STATUS_CHOICES, choices=STATUS_CHOICES
default=SIGNED_UP
) )
note = models.CharField( note = models.CharField(
@ -93,6 +91,10 @@ class RaidResponse(models.Model):
models.UniqueConstraint(fields=["raid", "character"], name="unique_character_raid_signup") 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): def clean(self):
# Make sure sign-offs are role-agnostic, but all other responses are not # Make sure sign-offs are role-agnostic, but all other responses are not
if self.status == RaidResponse.SIGNED_OFF: if self.status == RaidResponse.SIGNED_OFF:
@ -100,14 +102,16 @@ class RaidResponse(models.Model):
elif self.role is None: elif self.role is None:
raise ValidationError({"role": "This field is required."}) raise ValidationError({"role": "This field is required."})
def save(self, *args, **kwargs): # Set attendance to one of the default values if status was changed
# Set attendance if it hasn't been set manually if self.status != self._original_status:
if self.attendance is None:
if self.status >= RaidResponse.SIGNED_UP: if self.status >= RaidResponse.SIGNED_UP:
self.attendance = settings.DEFAULT_ATTENDANCE_ATTENDING # 1.0 by default self.attendance = settings.DEFAULT_ATTENDANCE_ATTENDING # 1.0 by default
else: else:
self.attendance = settings.DEFAULT_ATTENDANCE_NOT_ATTENDING # 0.0 by default self.attendance = settings.DEFAULT_ATTENDANCE_NOT_ATTENDING # 0.0 by default
def save(self, *args, **kwargs):
super().save(*args, **kwargs) super().save(*args, **kwargs)
self._original_status = self.status
def __str__(self): def __str__(self):
return super().__str__() # TODO? return super().__str__() # TODO?

View file

@ -41,14 +41,13 @@ class User(AbstractUser):
ordering = ["rank", "username"] ordering = ["rank", "username"]
def clean(self): def clean(self):
if not hasattr(self, "rank"):
self.rank = Rank.objects.last()
if hasattr(self, "main") and self.main.user != self: if hasattr(self, "main") and self.main.user != self:
raise ValidationError({"main": "Main character must be owned by user."}) raise ValidationError({"main": "Main character must be owned by user."})
@transaction.atomic @transaction.atomic
def save(self, *args, **kwargs): def save(self, *args, **kwargs):
if not hasattr(self, "rank"):
self.rank = Rank.objects.last()
if not hasattr(self, "main"): if not hasattr(self, "main"):
self.main = Character.objects.create( self.main = Character.objects.create(
user=None, user=None,