|
|
|
@ -1,4 +1,4 @@
|
|
|
|
|
from django.shortcuts import render, get_object_or_404
|
|
|
|
|
from django.shortcuts import render, get_object_or_404, redirect
|
|
|
|
|
from django.contrib.auth.decorators import login_required
|
|
|
|
|
from django.utils import timezone
|
|
|
|
|
from django.db.models.fields import DateTimeField
|
|
|
|
@ -6,6 +6,8 @@ from django.db.models import F, Count, Q, ExpressionWrapper
|
|
|
|
|
from .models import ShiftRegistration, Room, Shift, Helper
|
|
|
|
|
from django.views.generic import DetailView, ListView
|
|
|
|
|
from django.contrib.auth.mixins import LoginRequiredMixin
|
|
|
|
|
from django.contrib import messages
|
|
|
|
|
from .forms import HelperShift
|
|
|
|
|
|
|
|
|
|
# Create your views here.
|
|
|
|
|
def index(request):
|
|
|
|
@ -38,9 +40,38 @@ def shift_overview(request):
|
|
|
|
|
return render(request, "shift_overview.html", context)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ShiftDetail(LoginRequiredMixin, DetailView):
|
|
|
|
|
template_name = "shift_detail.html"
|
|
|
|
|
model = Shift
|
|
|
|
|
def add_helper_shift(self):
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@login_required()
|
|
|
|
|
def shift_detail(request, pk):
|
|
|
|
|
shift = get_object_or_404(Shift, pk=pk)
|
|
|
|
|
form = HelperShift()
|
|
|
|
|
if request.method == "POST":
|
|
|
|
|
form = HelperShift(request.POST)
|
|
|
|
|
if form.is_valid():
|
|
|
|
|
(reg, created) = ShiftRegistration.objects.get_or_create(
|
|
|
|
|
helper=form.cleaned_data["helper"], shift=shift
|
|
|
|
|
)
|
|
|
|
|
if created:
|
|
|
|
|
messages.add_message(
|
|
|
|
|
request,
|
|
|
|
|
messages.SUCCESS,
|
|
|
|
|
"Helfer erfolgreich zur Schicht hinzugefügt",
|
|
|
|
|
)
|
|
|
|
|
else:
|
|
|
|
|
messages.add_message(
|
|
|
|
|
request,
|
|
|
|
|
messages.WARNING,
|
|
|
|
|
"Helfer ist bereits für diese Schicht angemeldet",
|
|
|
|
|
)
|
|
|
|
|
return redirect("team:shift", pk=shift.pk)
|
|
|
|
|
context = {
|
|
|
|
|
"shift": shift,
|
|
|
|
|
"add_helper_form": form,
|
|
|
|
|
}
|
|
|
|
|
return render(request, "shift_detail.html", context)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class HelperDetail(LoginRequiredMixin, DetailView):
|
|
|
|
|