|
|
|
@ -11,31 +11,61 @@ from django.contrib import messages
|
|
|
|
|
from django.db import models
|
|
|
|
|
from django.core.paginator import Paginator
|
|
|
|
|
from .forms import BulkMessage, HelperShift, HelperMessage
|
|
|
|
|
from datetime import timedelta
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Create your views here.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def index(request):
|
|
|
|
|
pass
|
|
|
|
|
return redirect("team:shift_overview")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@login_required
|
|
|
|
|
def shift_overview(request):
|
|
|
|
|
checkin_count = Count(
|
|
|
|
|
Case(
|
|
|
|
|
When(
|
|
|
|
|
shiftregistration__state=ShiftRegistration.RegState.CHECKED_IN, then=1
|
|
|
|
|
),
|
|
|
|
|
output_field=models.IntegerField(),
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
context = {}
|
|
|
|
|
context["running_shifts"] = [
|
|
|
|
|
shift
|
|
|
|
|
for shift in Shift.with_reg_count()
|
|
|
|
|
context["running_shifts"] = (
|
|
|
|
|
Shift.with_reg_count()
|
|
|
|
|
.annotate(
|
|
|
|
|
checkin_count=Count(
|
|
|
|
|
Case(
|
|
|
|
|
When(
|
|
|
|
|
shiftregistration__state=ShiftRegistration.RegState.CHECKED_IN,
|
|
|
|
|
then=1,
|
|
|
|
|
),
|
|
|
|
|
output_field=models.IntegerField(),
|
|
|
|
|
)
|
|
|
|
|
),
|
|
|
|
|
end_at=ExpressionWrapper(
|
|
|
|
|
F("start_at") + F("duration"),
|
|
|
|
|
output_field=DateTimeField(),
|
|
|
|
|
)
|
|
|
|
|
F("start_at") + F("duration"), output_field=DateTimeField()
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
.filter(start_at__lte=timezone.now(), end_at__gte=timezone.now(), deleted=False)
|
|
|
|
|
.order_by("start_at")
|
|
|
|
|
]
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
context["next_shifts"] = (
|
|
|
|
|
Shift.with_reg_count()
|
|
|
|
|
.annotate(checkin_count=checkin_count)
|
|
|
|
|
.filter(
|
|
|
|
|
start_at__gt=timezone.now(),
|
|
|
|
|
start_at__lte=timezone.now() + timedelta(minutes=30),
|
|
|
|
|
deleted=False,
|
|
|
|
|
)
|
|
|
|
|
.order_by("start_at")
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# only Postgres supports DISTINCT on specific columns, SQLite does not support aggregates on datetime fields
|
|
|
|
|
context["next_shifts"] = filter(
|
|
|
|
|
context["next_shifts_per_room"] = filter(
|
|
|
|
|
lambda x: x is not None,
|
|
|
|
|
(
|
|
|
|
|
Shift.with_reg_count()
|
|
|
|
|