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