|
|
@ -3,6 +3,7 @@ import secrets
|
|
|
|
from django.shortcuts import reverse
|
|
|
|
from django.shortcuts import reverse
|
|
|
|
from datetime import timedelta
|
|
|
|
from datetime import timedelta
|
|
|
|
from django.utils import timezone
|
|
|
|
from django.utils import timezone
|
|
|
|
|
|
|
|
from django.db.models import F, Count, Q, ExpressionWrapper
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Room(models.Model):
|
|
|
|
class Room(models.Model):
|
|
|
@ -22,6 +23,8 @@ class Shift(models.Model):
|
|
|
|
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):
|
|
|
|
|
|
|
|
return (self.start_at <=timezone.now()) and (not self.has_ended())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Helper(models.Model):
|
|
|
|
class Helper(models.Model):
|
|
|
@ -41,6 +44,17 @@ class Helper(models.Model):
|
|
|
|
msg.save()
|
|
|
|
msg.save()
|
|
|
|
return token
|
|
|
|
return token
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# current or next shift
|
|
|
|
|
|
|
|
def important_shift(self):
|
|
|
|
|
|
|
|
ret = ShiftRegistration.objects.annotate(
|
|
|
|
|
|
|
|
shift_end=ExpressionWrapper(
|
|
|
|
|
|
|
|
F("shift__start_at") + F("shift__duration"),
|
|
|
|
|
|
|
|
output_field=models.DateTimeField(),
|
|
|
|
|
|
|
|
)).filter(helper=self, shift_end__gte=timezone.now()).order_by("shift__start_at").first()
|
|
|
|
|
|
|
|
if ret:
|
|
|
|
|
|
|
|
return ret.shift
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ShiftRegistration(models.Model):
|
|
|
|
class ShiftRegistration(models.Model):
|
|
|
|
class Meta:
|
|
|
|
class Meta:
|
|
|
|