|
|
@ -21,8 +21,10 @@ class Shift(models.Model):
|
|
|
|
# todo: add helper amount override field
|
|
|
|
# todo: add helper amount override field
|
|
|
|
def __str__(self):
|
|
|
|
def __str__(self):
|
|
|
|
return f"{self.room.name}: {self.start_at}"
|
|
|
|
return f"{self.room.name}: {self.start_at}"
|
|
|
|
|
|
|
|
|
|
|
|
def has_ended(self):
|
|
|
|
def has_ended(self):
|
|
|
|
return (self.start_at + self.duration) < timezone.now()
|
|
|
|
return (self.start_at + self.duration) < timezone.now()
|
|
|
|
|
|
|
|
|
|
|
|
def is_running(self):
|
|
|
|
def is_running(self):
|
|
|
|
return (self.start_at <= timezone.now()) and (not self.has_ended())
|
|
|
|
return (self.start_at <= timezone.now()) and (not self.has_ended())
|
|
|
|
|
|
|
|
|
|
|
@ -46,16 +48,21 @@ class Helper(models.Model):
|
|
|
|
|
|
|
|
|
|
|
|
# current or next shift
|
|
|
|
# current or next shift
|
|
|
|
def important_shift(self):
|
|
|
|
def important_shift(self):
|
|
|
|
ret = ShiftRegistration.objects.annotate(
|
|
|
|
ret = (
|
|
|
|
|
|
|
|
ShiftRegistration.objects.annotate(
|
|
|
|
shift_end=ExpressionWrapper(
|
|
|
|
shift_end=ExpressionWrapper(
|
|
|
|
F("shift__start_at") + F("shift__duration"),
|
|
|
|
F("shift__start_at") + F("shift__duration"),
|
|
|
|
output_field=models.DateTimeField(),
|
|
|
|
output_field=models.DateTimeField(),
|
|
|
|
)).filter(helper=self, shift_end__gte=timezone.now()).order_by("shift__start_at").first()
|
|
|
|
)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
.filter(helper=self, shift_end__gte=timezone.now())
|
|
|
|
|
|
|
|
.order_by("shift__start_at")
|
|
|
|
|
|
|
|
.first()
|
|
|
|
|
|
|
|
)
|
|
|
|
if ret:
|
|
|
|
if ret:
|
|
|
|
return ret.shift
|
|
|
|
return ret.shift
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ShiftRegistration(models.Model):
|
|
|
|
class ShiftRegistration(models.Model):
|
|
|
|
class Meta:
|
|
|
|
class Meta:
|
|
|
|
unique_together = (("shift", "helper"),)
|
|
|
|
unique_together = (("shift", "helper"),)
|
|
|
|