Compare commits
No commits in common. "5ea6e75d0ac940b3e4863805b79c8e0079ba3077" and "9af691f8caf92838d247037990cc51b7e647942e" have entirely different histories.
5ea6e75d0a
...
9af691f8ca
|
@ -1,18 +0,0 @@
|
||||||
# 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')]),
|
|
||||||
),
|
|
||||||
]
|
|
|
@ -26,9 +26,10 @@ class Raid(models.Model):
|
||||||
class Meta:
|
class Meta:
|
||||||
ordering = ["-date"]
|
ordering = ["-date"]
|
||||||
|
|
||||||
def clean(self):
|
def save(self, *args, **kwargs):
|
||||||
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}"
|
||||||
|
@ -70,7 +71,8 @@ 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(
|
||||||
|
@ -91,10 +93,6 @@ 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:
|
||||||
|
@ -102,16 +100,14 @@ 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."})
|
||||||
|
|
||||||
# Set attendance to one of the default values if status was changed
|
def save(self, *args, **kwargs):
|
||||||
if self.status != self._original_status:
|
# Set attendance if it hasn't been set manually
|
||||||
|
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?
|
||||||
|
|
|
@ -41,13 +41,14 @@ 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,
|
||||||
|
|
Loading…
Reference in a new issue