add initial shift signup flow

pull/1/head
parent 0566125299
commit 18b04a7102

@ -5,4 +5,8 @@ class RegisterForm(forms.Form):
name = forms.CharField(max_length=Helper.name.field.max_length, label="Name")
# actually verify phone number, lol
phone = forms.CharField(max_length=Helper.phone.field.max_length, label='Handynummer fuer Benarchrichtigungen')
okf = forms.BooleanField(label='Ich moechte SMS erhalten')
okf = forms.BooleanField(label='Ich moechte SMS erhalten')
# placeholder form for simple submit button use cases so we get csrf protection
class EmptyForm(forms.Form):
pass

@ -0,0 +1,18 @@
{% extends "base.html" %}
{% block title %}Schichtansicht{% endblock %}
{% block content %}
{%if is_registered%}
<div>Du bist zu dieser Schicht angemeldet</div>
{%endif%}
Ort: {{shift.room.name}}<br>
Start: {{shift.start_at}}<br>
Dauer: {{shift.duration}}<br>
{%if can_register%}
<form action="" method="post">
{% csrf_token %}
{{shift_form.as_p}}
<input type="submit" value="Anmelden">
</form>
{%endif%}
{% endblock %}

@ -7,5 +7,5 @@ urlpatterns = [
path('login/<slug:token>', views.login, name='token_login'),
path('logout', views.logout, name='token_logout'),
path('register', views.register, name='register'),
path('shift/<int:shiftid>', views.shift, name='shift'),
]

@ -1,10 +1,11 @@
from django.shortcuts import render, redirect, get_object_or_404
from .models import Shift, LoginToken, Helper
from .models import Shift, LoginToken, Helper, ShiftRegistration
import datetime
from django.db.models import F, Count
from .forms import RegisterForm
from .forms import RegisterForm, EmptyForm
def index(request):
del request.session['last_seen_shift']
# dont show shifts starting in <60 minutes?
# currently only sorts by date
free_shifts = Shift.objects.annotate(reg_count=Count('shiftregistration')).filter(start_at__gt=datetime.datetime.now(),
@ -20,6 +21,10 @@ def login(request, token):
tk.helper.number_validated=True
tk.helper.save()
request.session['token'] = token
# if the user was viewing a single shift before registering, they probably want to register for that
# shift so we redirect them there.
if request.session.get('last_seen_shift'):
return redirect('shift', shiftid=request.session['last_seen_shift'])
return redirect('index')
def logout(request):
@ -41,6 +46,35 @@ def register(request):
token = helper.send_confirmation()
request.session['token'] = token.pk
return render(request, 'wait_confirmation.html', {'helper':helper})
context['form']=RegisterForm()
return render(request, 'register.html', context)
return render(request, 'register.html', context)
def shift(request, shiftid):
shift = get_object_or_404(Shift, pk=shiftid)
helper = None
context = { 'can_register':False,
'is_registered':False,
'shift':shift,
'shift_form': EmptyForm,
}
# this currently ignores date/time
request.session['last_seen_shift'] = shiftid
if shift.room.required_helpers>shift.shiftregistration_set.count():
context['can_register'] = True
if request.session.get('token'):
helper = LoginToken.objects.get(pk=request.session['token']).helper
context['helper'] =helper
if ShiftRegistration.objects.filter(shift=shift, helper=helper).count()!=0:
context['is_registered']=True
context['can_register']=False
if request.method=='POST':
if EmptyForm(request.POST).is_valid():
if not helper:
# todo: add flash message that signup is required?
return redirect('register')
if context['can_register']:
s = ShiftRegistration(helper=helper, shift=shift)
s.save()
# redirect so page can be reloaded without resending post data
return redirect('shift', shiftid=shift.pk)
return render(request, 'shift.html', context)
Loading…
Cancel
Save