|
|
|
@ -1,18 +1,25 @@
|
|
|
|
|
from django.shortcuts import render, redirect, get_object_or_404
|
|
|
|
|
from .models import Shift, LoginToken, Helper, ShiftRegistration
|
|
|
|
|
import datetime
|
|
|
|
|
from django.db.models import F, Count
|
|
|
|
|
from django.db.models import F, Count, Q
|
|
|
|
|
from .forms import RegisterForm, EmptyForm
|
|
|
|
|
|
|
|
|
|
def index(request):
|
|
|
|
|
del request.session['last_seen_shift']
|
|
|
|
|
if request.session.get('last_seen_shift'):
|
|
|
|
|
del request.session['last_seen_shift']
|
|
|
|
|
# dont show shifts starting in <60 minutes?
|
|
|
|
|
# currently only sorts by date
|
|
|
|
|
context = {}
|
|
|
|
|
helper = None
|
|
|
|
|
if request.session.get('token'):
|
|
|
|
|
helper = LoginToken.objects.get(pk=request.session['token']).helper
|
|
|
|
|
context['helper'] = helper
|
|
|
|
|
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')
|
|
|
|
|
context = {'free_shifts': free_shifts}
|
|
|
|
|
if request.session.get('token'):
|
|
|
|
|
context['helper'] = LoginToken.objects.get(pk=request.session['token']).helper
|
|
|
|
|
if helper:
|
|
|
|
|
free_shifts = Shift.objects.annotate(reg_count=Count('shiftregistration')).filter(start_at__gt=datetime.datetime.now(),
|
|
|
|
|
room__required_helpers__gt=F('reg_count')).filter( ~Q(shiftregistration__helper=helper)).order_by('start_at')
|
|
|
|
|
context['free_shifts']= free_shifts
|
|
|
|
|
return render(request, 'shiftlist.html', context)
|
|
|
|
|
|
|
|
|
|
def login(request, token):
|
|
|
|
|