2
0
Fork 0

Add 'Nicht angetreten' button per helper to team shift detail

This commit is contained in:
Luca 2023-05-14 15:16:00 +02:00
parent 0347adc267
commit aef78ce251
5 changed files with 42 additions and 6 deletions

View File

@ -155,9 +155,15 @@ class ShiftRegistration(models.Model):
def __str__(self): def __str__(self):
return f"{self.helper.name}: {self.shift}" return f"{self.helper.name}: {self.shift}"
def is_pending(self):
return self.state == self.RegState.REGISTERED
def is_checked_in(self): def is_checked_in(self):
return self.state == self.RegState.CHECKED_IN 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): class Message(models.Model):
# remove limit and send long messages in multiple messages? # remove limit and send long messages in multiple messages?

View File

@ -0,0 +1,12 @@
{% extends "base.html" %}
{% block title %}Helfer*in wirklich sperren?{% endblock %}
{% block content %}
<h3 class="title">Helfer*in wirklich sperren?</h3>
<form method="POST">
{% csrf_token %}
<button class="button is-danger is-small" type="submit">Schicht als "nicht angetreten" markieren und Helfer*in sperren</button>
</form>
<a class="button mt-3" href="{% url 'team:shift' reg.shift.pk %}">Zurück</a>
{% endblock %}

View File

@ -27,16 +27,17 @@
<div class="column is-one-quarter"> <div class="column is-one-quarter">
<div class="box"> <div class="box">
<div class="is-flex is-align-items-center is-justify-content-space-between mb-2"> <div class="is-flex is-align-items-center is-justify-content-space-between mb-2">
<a class="is-size-4" href="{% url 'team:helper' reg.helper.pk %}">{{ reg.helper.name }}</a> <a class="is-size-4" href="{% url 'team:helper' reg.helper.pk %}"{% if reg.is_withdrawn %} style="text-decoration: line-through;"{% endif %}>{{ reg.helper.name }}</a>
<a class="button is-link is-small" href="tel:{{ reg.helper.phone }}">📞</a> <a class="button is-link is-small" href="tel:{{ reg.helper.phone }}">📞</a>
</div> </div>
<div class="buttons"> <div class="buttons">
{% if not reg.is_checked_in %} {% if reg.is_pending %}
<a class="button is-warning is-small" href="{% url 'team:checkin' reg.pk %}">Als angekommen markieren</a><br> <a class="button is-warning is-small" href="{% url 'team:checkin' reg.pk %}">Als angekommen markieren</a>
{% else %} <a class="button is-warning is-small" href="{% url 'team:unregister' reg.pk %}">Helfer*in abmelden</a>
<a class="button is-danger is-small" href="{% url 'team:mark_as_failed' reg.pk %}">Nicht angetreten</a>
{% elif reg.is_checked_in %}
<button class="button is-success is-small" style="pointer-events:none;"></button> <button class="button is-success is-small" style="pointer-events:none;"></button>
{% endif %} {% endif %}
<a class="button is-danger is-small" href="{% url 'team:unregister' reg.pk %}">Helfer*in abmelden</a>
</div> </div>
</div> </div>
</div> </div>

View File

@ -13,6 +13,7 @@ urlpatterns = [
path("helper/<int:pk>", views.HelperDetail.as_view(), name="helper"), path("helper/<int:pk>", views.HelperDetail.as_view(), name="helper"),
path("message/", views.bulk_message, name="bulk_message"), path("message/", views.bulk_message, name="bulk_message"),
path("checkin/<int:pk>", views.checkin, name="checkin"), path("checkin/<int:pk>", views.checkin, name="checkin"),
path("mark_as_failed/<int:pk>", views.mark_as_failed, name="mark_as_failed"),
path("remove_helper/<int:pk>", views.delete_shiftregistration, name="unregister"), path("remove_helper/<int:pk>", views.delete_shiftregistration, name="unregister"),
path("incoming/", views.incoming_messages, name="incoming_messages"), path("incoming/", views.incoming_messages, name="incoming_messages"),
path("incoming/<int:pk>", views.incoming_message, name="incoming_message"), path("incoming/<int:pk>", views.incoming_message, name="incoming_message"),

View File

@ -8,7 +8,7 @@ from django.views.generic import DetailView, ListView
from django.views.generic.edit import FormMixin from django.views.generic.edit import FormMixin
from django.contrib.auth.mixins import LoginRequiredMixin from django.contrib.auth.mixins import LoginRequiredMixin
from django.contrib import messages from django.contrib import messages
from django.db import models from django.db import models, transaction
from django.core.paginator import Paginator from django.core.paginator import Paginator
from .forms import BulkMessage, HelperShift, HelperMessage from .forms import BulkMessage, HelperShift, HelperMessage
from datetime import timedelta from datetime import timedelta
@ -279,6 +279,22 @@ def checkin(request, pk):
return redirect("team:shift", pk=reg.shift.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 @login_required
def delete_shiftregistration(request, pk): def delete_shiftregistration(request, pk):
reg = get_object_or_404(ShiftRegistration, pk=pk) reg = get_object_or_404(ShiftRegistration, pk=pk)