convert reg states to choices class

pull/1/head
parent a75baf537a
commit 5fdba3492d

@ -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)
# default is registered class RegState(models.TextChoices):
REGISTERED = "REG" # default is registered
CHECKED_IN = "CHECK" REGISTERED = "REG", "registriert"
# cancel via infopoint CHECKED_IN = "CHECK", "checkin"
CANCELED = "CANCEL" # cancel via infopoint
# did not attend shift CANCELED = "CANCEL", "abgemeldet"
FAILED = "FAIL" # did not attend shift
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):

@ -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")
) )

Loading…
Cancel
Save