diff --git a/shiftregister/app/models.py b/shiftregister/app/models.py index 197cc2e..550d79f 100644 --- a/shiftregister/app/models.py +++ b/shiftregister/app/models.py @@ -149,9 +149,9 @@ class ShiftRegistration(models.Model): def __str__(self): return f"{self.helper.name}: {self.shift}" - + def is_checked_in(self): - return self.state==self.RegState.CHECKED_IN + return self.state == self.RegState.CHECKED_IN class Message(models.Model): diff --git a/shiftregister/signage/views.py b/shiftregister/signage/views.py index cd8e310..a506c6e 100644 --- a/shiftregister/signage/views.py +++ b/shiftregister/signage/views.py @@ -7,6 +7,7 @@ from .models import TeamBackup from .models import Shift from .forms import TeamBackupForm from datetime import timedelta +from django.db.models import DateTimeField # Create your views here. @login_required @@ -16,9 +17,15 @@ def worklist(request): ) shifts = ( Shift.with_reg_count() + .annotate( + end_at=ExpressionWrapper( + F("start_at") + F("duration"), + output_field=DateTimeField(), + ) + ) .filter( help_wanted, - start_at__gt=timezone.now(), + end_at__gte=timezone.now(), deleted=False, ) .order_by("start_at", "room_id") @@ -48,9 +55,15 @@ def terminal(request): ) shifts = ( Shift.with_reg_count() + .annotate( + end_at=ExpressionWrapper( + F("start_at") + F("duration"), + output_field=DateTimeField(), + ) + ) .filter( help_wanted, - start_at__gt=timezone.now() - timedelta(minutes=20), + end_at__gte=timezone.now(), deleted=False, ) .order_by("start_at", "room_id") diff --git a/shiftregister/team/forms.py b/shiftregister/team/forms.py index 1f94351..ba7c2ce 100644 --- a/shiftregister/team/forms.py +++ b/shiftregister/team/forms.py @@ -10,10 +10,9 @@ class NameField(forms.ModelChoiceField): def label_from_instance(self, user): return f"{user.name} ({(str(user.phone))[-3:]})" + class HelperShift(forms.Form): - helper = NameField( - label="Helfer*in", queryset=Helper.objects.order_by("name") - ) + helper = NameField(label="Helfer*in", queryset=Helper.objects.order_by("name")) class BulkMessage(forms.Form): diff --git a/shiftregister/team/urls.py b/shiftregister/team/urls.py index 884f6e5..a71118e 100644 --- a/shiftregister/team/urls.py +++ b/shiftregister/team/urls.py @@ -11,5 +11,5 @@ urlpatterns = [ path("shift/", views.shift_detail, name="shift"), path("helper/", views.HelperDetail.as_view(), name="helper"), path("message/", views.bulk_message, name="bulk_message"), - path("checkin/", views.checkin, name="checkin" ), + path("checkin/", views.checkin, name="checkin"), ] diff --git a/shiftregister/team/views.py b/shiftregister/team/views.py index a854daa..2b26a13 100644 --- a/shiftregister/team/views.py +++ b/shiftregister/team/views.py @@ -141,17 +141,24 @@ class FreeShiftList(ShiftList): ) & Q(room__required_helpers__gt=F("reg_count")) return ( Shift.with_reg_count() + .annotate( + end_at=ExpressionWrapper( + F("start_at") + F("duration"), + output_field=DateTimeField(), + ) + ) .filter( help_wanted, - start_at__gt=timezone.now(), - deleted = False, + end_at__gte=timezone.now(), + deleted=False, ) .order_by("start_at", "room_id") ) + @login_required def checkin(request, pk): reg = get_object_or_404(ShiftRegistration, pk=pk) reg.state = reg.RegState.CHECKED_IN reg.save() - return redirect("team:shift", pk=reg.shift.pk) \ No newline at end of file + return redirect("team:shift", pk=reg.shift.pk)