2
0
Fork 0

convert reg states to choices class

This commit is contained in:
Andreas (@xAndy) Zimmermann 2022-05-10 23:04:47 +02:00
parent a75baf537a
commit 5fdba3492d
2 changed files with 24 additions and 20 deletions

View File

@ -34,8 +34,8 @@ class Shift(models.Model):
Case(
When(
shiftregistration__state__in=[
ShiftRegistration.REGISTERED,
ShiftRegistration.CHECKED_IN,
ShiftRegistration.RegState.REGISTERED,
ShiftRegistration.RegState.CHECKED_IN,
],
then=1,
),
@ -55,7 +55,10 @@ class Shift(models.Model):
def registration_count(self):
return self.shiftregistration_set.filter(
state__in=[ShiftRegistration.REGISTERED, ShiftRegistration.CHECKED_IN]
state__in=[
ShiftRegistration.RegState.REGISTERED,
ShiftRegistration.RegState.CHECKED_IN,
]
).count()
@ -86,7 +89,10 @@ class Helper(models.Model):
helper=self,
shift_end__gte=timezone.now(),
shift__deleted=False,
state__in=[ShiftRegistration.REGISTERED, ShiftRegistration.CHECKED_IN],
state__in=[
ShiftRegistration.RegState.REGISTERED,
ShiftRegistration.RegState.CHECKED_IN,
],
)
.order_by("shift__start_at")
.first()
@ -104,24 +110,19 @@ class ShiftRegistration(models.Model):
helper = models.ForeignKey(Helper, on_delete=models.CASCADE)
reminder_sent = models.BooleanField(default=False)
# default is registered
REGISTERED = "REG"
CHECKED_IN = "CHECK"
# cancel via infopoint
CANCELED = "CANCEL"
# did not attend shift
FAILED = "FAIL"
class RegState(models.TextChoices):
# default is registered
REGISTERED = "REG", "registriert"
CHECKED_IN = "CHECK", "checkin"
# cancel via infopoint
CANCELED = "CANCEL", "abgemeldet"
# did not attend shift
FAILED = "FAIL", "nicht angetreten"
STATE_CHOICES = [
(REGISTERED, "registriert"),
(CHECKED_IN, "checkin"),
(CANCELED, "abgemeldet"),
(FAILED, "nicht angetreten"),
]
state = models.CharField(
max_length=7,
choices=STATE_CHOICES,
default=REGISTERED,
choices=RegState.choices,
default=RegState.REGISTERED,
)
def can_cancel(self):

View File

@ -28,7 +28,10 @@ def index(request):
reg.shift
for reg in request.helper.shiftregistration_set.filter(
shift__start_at__gt=timezone.now(),
state__in=[ShiftRegistration.REGISTERED, ShiftRegistration.CHECKED_IN],
state__in=[
ShiftRegistration.RegState.REGISTERED,
ShiftRegistration.RegState.CHECKED_IN,
],
).order_by("shift__start_at")
)