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

View File

@ -28,7 +28,10 @@ def index(request):
reg.shift reg.shift
for reg in request.helper.shiftregistration_set.filter( for reg in request.helper.shiftregistration_set.filter(
shift__start_at__gt=timezone.now(), 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") ).order_by("shift__start_at")
) )