|
|
|
@ -14,14 +14,12 @@ def index(request):
|
|
|
|
|
# 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["my_shifts"] = helper.shiftregistration_set.filter(
|
|
|
|
|
if request.helper:
|
|
|
|
|
context["my_shifts"] = request.helper.shiftregistration_set.filter(
|
|
|
|
|
shift__start_at__gt=timezone.now()
|
|
|
|
|
).order_by("shift__start_at")
|
|
|
|
|
context["current_shift"] = (
|
|
|
|
|
helper.shiftregistration_set.annotate(
|
|
|
|
|
request.helper.shiftregistration_set.annotate(
|
|
|
|
|
shift_end=ExpressionWrapper(
|
|
|
|
|
F("shift__start_at") + F("shift__duration"),
|
|
|
|
|
output_field=DateTimeField(),
|
|
|
|
@ -36,13 +34,13 @@ def index(request):
|
|
|
|
|
.filter(start_at__gt=timezone.now(), room__required_helpers__gt=F("reg_count"))
|
|
|
|
|
.order_by("start_at")
|
|
|
|
|
)
|
|
|
|
|
if helper:
|
|
|
|
|
if request.helper:
|
|
|
|
|
free_shifts = (
|
|
|
|
|
Shift.objects.annotate(reg_count=Count("shiftregistration"))
|
|
|
|
|
.filter(
|
|
|
|
|
start_at__gt=timezone.now(), room__required_helpers__gt=F("reg_count")
|
|
|
|
|
)
|
|
|
|
|
.filter(~Q(shiftregistration__helper=helper))
|
|
|
|
|
.filter(~Q(shiftregistration__helper=request.helper))
|
|
|
|
|
.order_by("start_at")
|
|
|
|
|
)
|
|
|
|
|
context["free_shifts"] = free_shifts
|
|
|
|
@ -75,7 +73,9 @@ def logout(request):
|
|
|
|
|
|
|
|
|
|
def register(request):
|
|
|
|
|
# handle number already being registered(resend message?)
|
|
|
|
|
if request.session.get("token"):
|
|
|
|
|
if request.helper:
|
|
|
|
|
if request.session.get("last_seen_shift"):
|
|
|
|
|
return redirect("shift", shiftid=request.session["last_seen_shift"])
|
|
|
|
|
return redirect("index")
|
|
|
|
|
context = {}
|
|
|
|
|
if request.method == "POST":
|
|
|
|
@ -102,7 +102,7 @@ def register(request):
|
|
|
|
|
|
|
|
|
|
def shift(request, shiftid):
|
|
|
|
|
shift = get_object_or_404(Shift, pk=shiftid)
|
|
|
|
|
helper = None
|
|
|
|
|
helper = request.helper
|
|
|
|
|
context = {
|
|
|
|
|
"can_register": False,
|
|
|
|
|
"is_registered": False,
|
|
|
|
@ -114,8 +114,7 @@ def shift(request, shiftid):
|
|
|
|
|
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
|
|
|
|
|
if helper:
|
|
|
|
|
context["helper"] = helper
|
|
|
|
|
reg = ShiftRegistration.objects.filter(shift=shift, helper=helper)
|
|
|
|
|
if reg:
|
|
|
|
@ -126,7 +125,6 @@ def shift(request, shiftid):
|
|
|
|
|
if request.method == "POST":
|
|
|
|
|
if EmptyForm(request.POST).is_valid():
|
|
|
|
|
if not helper:
|
|
|
|
|
# todo: add flash message that signup is required?
|
|
|
|
|
messages.add_message(
|
|
|
|
|
request,
|
|
|
|
|
messages.WARNING,
|
|
|
|
@ -160,9 +158,8 @@ def cancel(request, shiftid):
|
|
|
|
|
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)
|
|
|
|
|
reg = get_object_or_404(ShiftRegistration, helper=request.helper, shift=shift)
|
|
|
|
|
if reg.can_cancel():
|
|
|
|
|
reg.delete()
|
|
|
|
|
messages.add_message(
|
|
|
|
|