|
|
@ -11,31 +11,61 @@ from django.contrib import messages
|
|
|
|
from django.db import models
|
|
|
|
from django.db import models
|
|
|
|
from django.core.paginator import Paginator
|
|
|
|
from django.core.paginator import Paginator
|
|
|
|
from .forms import BulkMessage, HelperShift, HelperMessage
|
|
|
|
from .forms import BulkMessage, HelperShift, HelperMessage
|
|
|
|
|
|
|
|
from datetime import timedelta
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Create your views here.
|
|
|
|
# Create your views here.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def index(request):
|
|
|
|
def index(request):
|
|
|
|
pass
|
|
|
|
return redirect("team:shift_overview")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@login_required
|
|
|
|
@login_required
|
|
|
|
def shift_overview(request):
|
|
|
|
def shift_overview(request):
|
|
|
|
|
|
|
|
checkin_count = Count(
|
|
|
|
|
|
|
|
Case(
|
|
|
|
|
|
|
|
When(
|
|
|
|
|
|
|
|
shiftregistration__state=ShiftRegistration.RegState.CHECKED_IN, then=1
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
output_field=models.IntegerField(),
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
context = {}
|
|
|
|
context = {}
|
|
|
|
context["running_shifts"] = [
|
|
|
|
context["running_shifts"] = (
|
|
|
|
shift
|
|
|
|
Shift.with_reg_count()
|
|
|
|
for shift in Shift.with_reg_count()
|
|
|
|
|
|
|
|
.annotate(
|
|
|
|
.annotate(
|
|
|
|
end_at=ExpressionWrapper(
|
|
|
|
checkin_count=Count(
|
|
|
|
F("start_at") + F("duration"),
|
|
|
|
Case(
|
|
|
|
output_field=DateTimeField(),
|
|
|
|
When(
|
|
|
|
|
|
|
|
shiftregistration__state=ShiftRegistration.RegState.CHECKED_IN,
|
|
|
|
|
|
|
|
then=1,
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
output_field=models.IntegerField(),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
end_at=ExpressionWrapper(
|
|
|
|
|
|
|
|
F("start_at") + F("duration"), output_field=DateTimeField()
|
|
|
|
|
|
|
|
),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
.filter(start_at__lte=timezone.now(), end_at__gte=timezone.now(), deleted=False)
|
|
|
|
.filter(start_at__lte=timezone.now(), end_at__gte=timezone.now(), deleted=False)
|
|
|
|
.order_by("start_at")
|
|
|
|
.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
|
|
|
|
# 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,
|
|
|
|
lambda x: x is not None,
|
|
|
|
(
|
|
|
|
(
|
|
|
|
Shift.with_reg_count()
|
|
|
|
Shift.with_reg_count()
|
|
|
|