|
|
@ -61,6 +61,7 @@ def shift(request, shiftid):
|
|
|
|
helper = None
|
|
|
|
helper = None
|
|
|
|
context = { 'can_register':False,
|
|
|
|
context = { 'can_register':False,
|
|
|
|
'is_registered':False,
|
|
|
|
'is_registered':False,
|
|
|
|
|
|
|
|
'can_cancel': False,
|
|
|
|
'shift':shift,
|
|
|
|
'shift':shift,
|
|
|
|
'shift_form': EmptyForm,
|
|
|
|
'shift_form': EmptyForm,
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -71,9 +72,12 @@ def shift(request, shiftid):
|
|
|
|
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
|
|
|
|
if ShiftRegistration.objects.filter(shift=shift, helper=helper).count()!=0:
|
|
|
|
reg = ShiftRegistration.objects.filter(shift=shift, helper=helper)
|
|
|
|
|
|
|
|
if reg:
|
|
|
|
context['is_registered']=True
|
|
|
|
context['is_registered']=True
|
|
|
|
context['can_register']=False
|
|
|
|
context['can_register']=False
|
|
|
|
|
|
|
|
if reg[0].can_cancel():
|
|
|
|
|
|
|
|
context['can_cancel'] = True
|
|
|
|
if request.method=='POST':
|
|
|
|
if request.method=='POST':
|
|
|
|
if EmptyForm(request.POST).is_valid():
|
|
|
|
if EmptyForm(request.POST).is_valid():
|
|
|
|
if not helper:
|
|
|
|
if not helper:
|
|
|
@ -84,4 +88,18 @@ def shift(request, shiftid):
|
|
|
|
s.save()
|
|
|
|
s.save()
|
|
|
|
# redirect so page can be reloaded without resending post data
|
|
|
|
# redirect so page can be reloaded without resending post data
|
|
|
|
return redirect('shift', shiftid=shift.pk)
|
|
|
|
return redirect('shift', shiftid=shift.pk)
|
|
|
|
return render(request, 'shift.html', context)
|
|
|
|
return render(request, 'shift.html', context)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def cancel(request, shiftid):
|
|
|
|
|
|
|
|
if request.method!='POST':
|
|
|
|
|
|
|
|
return redirect('shift', shiftid=shiftid)
|
|
|
|
|
|
|
|
if not EmptyForm(request.POST).is_valid():
|
|
|
|
|
|
|
|
return redirect('shift', shiftid=shiftid)
|
|
|
|
|
|
|
|
if not request.session.get('token'):
|
|
|
|
|
|
|
|
return redirect('shift', shiftid=shiftid)
|
|
|
|
|
|
|
|
helper = LoginToken.objects.get(pk=request.session['token']).helper
|
|
|
|
|
|
|
|
shift = get_object_or_404(Shift, pk=shiftid)
|
|
|
|
|
|
|
|
reg = get_object_or_404(ShiftRegistration, helper=helper, shift=shift)
|
|
|
|
|
|
|
|
if reg.can_cancel():
|
|
|
|
|
|
|
|
reg.delete()
|
|
|
|
|
|
|
|
return redirect('shift', shiftid=shiftid)
|