|
|
@ -11,6 +11,7 @@ from django.contrib import messages
|
|
|
|
def index(request):
|
|
|
|
def index(request):
|
|
|
|
if request.session.get("last_seen_shift"):
|
|
|
|
if request.session.get("last_seen_shift"):
|
|
|
|
del request.session["last_seen_shift"]
|
|
|
|
del request.session["last_seen_shift"]
|
|
|
|
|
|
|
|
|
|
|
|
# dont show shifts starting in <60 minutes?
|
|
|
|
# dont show shifts starting in <60 minutes?
|
|
|
|
# currently only sorts by date
|
|
|
|
# currently only sorts by date
|
|
|
|
context = {}
|
|
|
|
context = {}
|
|
|
@ -29,11 +30,13 @@ def index(request):
|
|
|
|
.order_by("shift__start_at")
|
|
|
|
.order_by("shift__start_at")
|
|
|
|
.first()
|
|
|
|
.first()
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
free_shifts = (
|
|
|
|
free_shifts = (
|
|
|
|
Shift.objects.annotate(reg_count=Count("shiftregistration"))
|
|
|
|
Shift.objects.annotate(reg_count=Count("shiftregistration"))
|
|
|
|
.filter(start_at__gt=timezone.now(), room__required_helpers__gt=F("reg_count"))
|
|
|
|
.filter(start_at__gt=timezone.now(), room__required_helpers__gt=F("reg_count"))
|
|
|
|
.order_by("start_at")
|
|
|
|
.order_by("start_at")
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
if request.helper:
|
|
|
|
if request.helper:
|
|
|
|
free_shifts = (
|
|
|
|
free_shifts = (
|
|
|
|
Shift.objects.annotate(reg_count=Count("shiftregistration"))
|
|
|
|
Shift.objects.annotate(reg_count=Count("shiftregistration"))
|
|
|
@ -43,6 +46,7 @@ def index(request):
|
|
|
|
.filter(~Q(shiftregistration__helper=request.helper))
|
|
|
|
.filter(~Q(shiftregistration__helper=request.helper))
|
|
|
|
.order_by("start_at")
|
|
|
|
.order_by("start_at")
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
context["free_shifts"] = free_shifts
|
|
|
|
context["free_shifts"] = free_shifts
|
|
|
|
return render(request, "shiftlist.html", context)
|
|
|
|
return render(request, "shiftlist.html", context)
|
|
|
|
|
|
|
|
|
|
|
@ -57,17 +61,21 @@ def login(request, token):
|
|
|
|
messages.SUCCESS,
|
|
|
|
messages.SUCCESS,
|
|
|
|
"Nummer bestätigt, Du kannst dich jetzt für Schichten anmelden",
|
|
|
|
"Nummer bestätigt, Du kannst dich jetzt für Schichten anmelden",
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
request.session["token"] = token
|
|
|
|
request.session["token"] = token
|
|
|
|
|
|
|
|
|
|
|
|
# if the user was viewing a single shift before registering, they probably want to register for that
|
|
|
|
# if the user was viewing a single shift before registering, they probably want to register for that
|
|
|
|
# shift so we redirect them there.
|
|
|
|
# shift so we redirect them there.
|
|
|
|
if request.session.get("last_seen_shift"):
|
|
|
|
if request.session.get("last_seen_shift"):
|
|
|
|
return redirect("shift", shiftid=request.session["last_seen_shift"])
|
|
|
|
return redirect("shift", shiftid=request.session["last_seen_shift"])
|
|
|
|
|
|
|
|
|
|
|
|
return redirect("index")
|
|
|
|
return redirect("index")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def logout(request):
|
|
|
|
def logout(request):
|
|
|
|
if request.session.get("token"):
|
|
|
|
if request.session.get("token"):
|
|
|
|
del request.session["token"]
|
|
|
|
del request.session["token"]
|
|
|
|
|
|
|
|
|
|
|
|
return redirect("index")
|
|
|
|
return redirect("index")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -76,13 +84,16 @@ def register(request):
|
|
|
|
if request.helper:
|
|
|
|
if request.helper:
|
|
|
|
if request.session.get("last_seen_shift"):
|
|
|
|
if request.session.get("last_seen_shift"):
|
|
|
|
return redirect("shift", shiftid=request.session["last_seen_shift"])
|
|
|
|
return redirect("shift", shiftid=request.session["last_seen_shift"])
|
|
|
|
|
|
|
|
|
|
|
|
return redirect("index")
|
|
|
|
return redirect("index")
|
|
|
|
|
|
|
|
|
|
|
|
context = {}
|
|
|
|
context = {}
|
|
|
|
if request.method == "POST":
|
|
|
|
if request.method == "POST":
|
|
|
|
form = RegisterForm(request.POST)
|
|
|
|
form = RegisterForm(request.POST)
|
|
|
|
if not form.is_valid():
|
|
|
|
if not form.is_valid():
|
|
|
|
context["form"] = form
|
|
|
|
context["form"] = form
|
|
|
|
return render(request, "register.html", context)
|
|
|
|
return render(request, "register.html", context)
|
|
|
|
|
|
|
|
|
|
|
|
helper = Helper(
|
|
|
|
helper = Helper(
|
|
|
|
name=form.cleaned_data["name"], phone=form.cleaned_data["phone"]
|
|
|
|
name=form.cleaned_data["name"], phone=form.cleaned_data["phone"]
|
|
|
|
)
|
|
|
|
)
|
|
|
@ -95,7 +106,9 @@ def register(request):
|
|
|
|
messages.INFO,
|
|
|
|
messages.INFO,
|
|
|
|
f"DEBUG: login token: {token.get_absolute_url()}",
|
|
|
|
f"DEBUG: login token: {token.get_absolute_url()}",
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
return render(request, "wait_confirmation.html", {"helper": helper})
|
|
|
|
return render(request, "wait_confirmation.html", {"helper": helper})
|
|
|
|
|
|
|
|
|
|
|
|
context["form"] = RegisterForm()
|
|
|
|
context["form"] = RegisterForm()
|
|
|
|
return render(request, "register.html", context)
|
|
|
|
return render(request, "register.html", context)
|
|
|
|
|
|
|
|
|
|
|
@ -110,10 +123,12 @@ def shift(request, shiftid):
|
|
|
|
"shift": shift,
|
|
|
|
"shift": shift,
|
|
|
|
"shift_form": EmptyForm,
|
|
|
|
"shift_form": EmptyForm,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# this currently ignores date/time
|
|
|
|
# this currently ignores date/time
|
|
|
|
request.session["last_seen_shift"] = shiftid
|
|
|
|
request.session["last_seen_shift"] = shiftid
|
|
|
|
if shift.room.required_helpers > shift.shiftregistration_set.count():
|
|
|
|
if shift.room.required_helpers > shift.shiftregistration_set.count():
|
|
|
|
context["can_register"] = True
|
|
|
|
context["can_register"] = True
|
|
|
|
|
|
|
|
|
|
|
|
if helper:
|
|
|
|
if helper:
|
|
|
|
context["helper"] = helper
|
|
|
|
context["helper"] = helper
|
|
|
|
reg = ShiftRegistration.objects.filter(shift=shift, helper=helper)
|
|
|
|
reg = ShiftRegistration.objects.filter(shift=shift, helper=helper)
|
|
|
@ -122,6 +137,7 @@ def shift(request, shiftid):
|
|
|
|
context["can_register"] = False
|
|
|
|
context["can_register"] = False
|
|
|
|
if reg[0].can_cancel():
|
|
|
|
if reg[0].can_cancel():
|
|
|
|
context["can_cancel"] = True
|
|
|
|
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:
|
|
|
@ -148,6 +164,7 @@ def shift(request, shiftid):
|
|
|
|
)
|
|
|
|
)
|
|
|
|
# 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)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -158,6 +175,7 @@ def cancel(request, shiftid):
|
|
|
|
return redirect("shift", shiftid=shiftid)
|
|
|
|
return redirect("shift", shiftid=shiftid)
|
|
|
|
if not request.session.get("token"):
|
|
|
|
if not request.session.get("token"):
|
|
|
|
return redirect("shift", shiftid=shiftid)
|
|
|
|
return redirect("shift", shiftid=shiftid)
|
|
|
|
|
|
|
|
|
|
|
|
shift = get_object_or_404(Shift, pk=shiftid)
|
|
|
|
shift = get_object_or_404(Shift, pk=shiftid)
|
|
|
|
reg = get_object_or_404(ShiftRegistration, helper=request.helper, shift=shift)
|
|
|
|
reg = get_object_or_404(ShiftRegistration, helper=request.helper, shift=shift)
|
|
|
|
if reg.can_cancel():
|
|
|
|
if reg.can_cancel():
|
|
|
@ -173,4 +191,5 @@ def cancel(request, shiftid):
|
|
|
|
messages.WARNING,
|
|
|
|
messages.WARNING,
|
|
|
|
"Abmeldung nicht (mehr) möglich, bitte wende dich an den Infopoint",
|
|
|
|
"Abmeldung nicht (mehr) möglich, bitte wende dich an den Infopoint",
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
return redirect("shift", shiftid=shiftid)
|
|
|
|
return redirect("shift", shiftid=shiftid)
|
|
|
|