diff --git a/shiftregister/app/models.py b/shiftregister/app/models.py index ea3931c..70fc6ff 100644 --- a/shiftregister/app/models.py +++ b/shiftregister/app/models.py @@ -155,9 +155,15 @@ class ShiftRegistration(models.Model): def __str__(self): return f"{self.helper.name}: {self.shift}" + def is_pending(self): + return self.state == self.RegState.REGISTERED + def is_checked_in(self): return self.state == self.RegState.CHECKED_IN + def is_withdrawn(self): + return self.state in (self.RegState.CANCELED, self.RegState.FAILED) + class Message(models.Model): # remove limit and send long messages in multiple messages? diff --git a/shiftregister/team/templates/molly_guard.html b/shiftregister/team/templates/molly_guard.html new file mode 100644 index 0000000..b531af1 --- /dev/null +++ b/shiftregister/team/templates/molly_guard.html @@ -0,0 +1,12 @@ +{% extends "base.html" %} + +{% block title %}Helfer*in wirklich sperren?{% endblock %} + +{% block content %} +

Helfer*in wirklich sperren?

+
+ {% csrf_token %} + +
+Zurück +{% endblock %} diff --git a/shiftregister/team/templates/shift_detail.html b/shiftregister/team/templates/shift_detail.html index 3932909..7dc2334 100644 --- a/shiftregister/team/templates/shift_detail.html +++ b/shiftregister/team/templates/shift_detail.html @@ -27,16 +27,17 @@
-{% if not reg.is_checked_in %} - Als angekommen markieren
-{% else %} +{% if reg.is_pending %} + Als angekommen markieren + Helfer*in abmelden + Nicht angetreten +{% elif reg.is_checked_in %} {% endif %} - Helfer*in abmelden
diff --git a/shiftregister/team/urls.py b/shiftregister/team/urls.py index c76bf56..6c044a1 100644 --- a/shiftregister/team/urls.py +++ b/shiftregister/team/urls.py @@ -13,6 +13,7 @@ urlpatterns = [ path("helper/", views.HelperDetail.as_view(), name="helper"), path("message/", views.bulk_message, name="bulk_message"), path("checkin/", views.checkin, name="checkin"), + path("mark_as_failed/", views.mark_as_failed, name="mark_as_failed"), path("remove_helper/", views.delete_shiftregistration, name="unregister"), path("incoming/", views.incoming_messages, name="incoming_messages"), path("incoming/", views.incoming_message, name="incoming_message"), diff --git a/shiftregister/team/views.py b/shiftregister/team/views.py index f119157..0425b2d 100644 --- a/shiftregister/team/views.py +++ b/shiftregister/team/views.py @@ -8,7 +8,7 @@ from django.views.generic import DetailView, ListView from django.views.generic.edit import FormMixin from django.contrib.auth.mixins import LoginRequiredMixin from django.contrib import messages -from django.db import models +from django.db import models, transaction from django.core.paginator import Paginator from .forms import BulkMessage, HelperShift, HelperMessage from datetime import timedelta @@ -279,6 +279,22 @@ def checkin(request, pk): return redirect("team:shift", pk=reg.shift.pk) +@login_required +def mark_as_failed(request, pk): + reg = get_object_or_404(ShiftRegistration, pk=pk) + + if request.method == "POST": + with transaction.atomic(): + reg.state = reg.RegState.FAILED + reg.save() + + # TODO: Mark helper as barred from further shift registrations (and delete pending existing ones) + + return redirect("team:shift", pk=reg.shift.pk) + + return render(request, "molly_guard.html", {"reg": reg}) + + @login_required def delete_shiftregistration(request, pk): reg = get_object_or_404(ShiftRegistration, pk=pk)