|
|
@ -1,8 +1,10 @@
|
|
|
|
from django.shortcuts import render, redirect, get_object_or_404
|
|
|
|
from django.shortcuts import render, redirect, get_object_or_404
|
|
|
|
from .models import Shift, LoginToken, Helper, ShiftRegistration
|
|
|
|
from .models import Shift, LoginToken, Helper, ShiftRegistration
|
|
|
|
import datetime
|
|
|
|
import datetime
|
|
|
|
from django.db.models import F, Count, Q
|
|
|
|
from django.db.models import F, Count, Q, ExpressionWrapper
|
|
|
|
from .forms import RegisterForm, EmptyForm
|
|
|
|
from .forms import RegisterForm, EmptyForm
|
|
|
|
|
|
|
|
from django.db.models.fields import DateTimeField
|
|
|
|
|
|
|
|
from pprint import pprint
|
|
|
|
|
|
|
|
|
|
|
|
def index(request):
|
|
|
|
def index(request):
|
|
|
|
if request.session.get('last_seen_shift'):
|
|
|
|
if request.session.get('last_seen_shift'):
|
|
|
@ -14,6 +16,8 @@ def index(request):
|
|
|
|
if request.session.get('token'):
|
|
|
|
if request.session.get('token'):
|
|
|
|
helper = LoginToken.objects.get(pk=request.session['token']).helper
|
|
|
|
helper = LoginToken.objects.get(pk=request.session['token']).helper
|
|
|
|
context['helper'] = helper
|
|
|
|
context['helper'] = helper
|
|
|
|
|
|
|
|
context['my_shifts'] = helper.shiftregistration_set.filter(shift__start_at__gt=datetime.datetime.now()).order_by('shift__start_at')
|
|
|
|
|
|
|
|
context['current_shift'] = next(iter(helper.shiftregistration_set.annotate(shift_end=ExpressionWrapper(F('shift__start_at')+F('shift__duration'), output_field=DateTimeField())).filter(shift__start_at__lte=datetime.datetime.now(), shift_end__gte=datetime.datetime.now()).order_by('shift__start_at')[:1]), None)
|
|
|
|
free_shifts = Shift.objects.annotate(reg_count=Count('shiftregistration')).filter(start_at__gt=datetime.datetime.now(),
|
|
|
|
free_shifts = Shift.objects.annotate(reg_count=Count('shiftregistration')).filter(start_at__gt=datetime.datetime.now(),
|
|
|
|
room__required_helpers__gt=F('reg_count')).order_by('start_at')
|
|
|
|
room__required_helpers__gt=F('reg_count')).order_by('start_at')
|
|
|
|
if helper:
|
|
|
|
if helper:
|
|
|
|