|
|
@ -2,11 +2,12 @@ from django.shortcuts import render, get_object_or_404, redirect
|
|
|
|
from django.contrib.auth.decorators import login_required
|
|
|
|
from django.contrib.auth.decorators import login_required
|
|
|
|
from django.utils import timezone
|
|
|
|
from django.utils import timezone
|
|
|
|
from django.db.models.fields import DateTimeField
|
|
|
|
from django.db.models.fields import DateTimeField
|
|
|
|
from django.db.models import F, Count, Q, ExpressionWrapper
|
|
|
|
from django.db.models import F, Count, Q, ExpressionWrapper, Case, When
|
|
|
|
from .models import ShiftRegistration, Room, Shift, Helper, Message
|
|
|
|
from .models import ShiftRegistration, Room, Shift, Helper, Message
|
|
|
|
from django.views.generic import DetailView, ListView
|
|
|
|
from django.views.generic import DetailView, ListView
|
|
|
|
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 .forms import BulkMessage, HelperShift
|
|
|
|
from .forms import BulkMessage, HelperShift
|
|
|
|
|
|
|
|
|
|
|
|
# Create your views here.
|
|
|
|
# Create your views here.
|
|
|
@ -117,6 +118,55 @@ def bulk_message(request):
|
|
|
|
return render(request, "bulk_message.html", context)
|
|
|
|
return render(request, "bulk_message.html", context)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@login_required
|
|
|
|
|
|
|
|
def bulk_message_helped(request):
|
|
|
|
|
|
|
|
form = BulkMessage()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if request.method == "POST":
|
|
|
|
|
|
|
|
form = BulkMessage(request.POST)
|
|
|
|
|
|
|
|
if form.is_valid():
|
|
|
|
|
|
|
|
helpers = Helper.objects.annotate(
|
|
|
|
|
|
|
|
shift_count=Count(
|
|
|
|
|
|
|
|
Case(
|
|
|
|
|
|
|
|
When(
|
|
|
|
|
|
|
|
shiftregistration__state__in=[
|
|
|
|
|
|
|
|
ShiftRegistration.RegState.CHECKED_IN,
|
|
|
|
|
|
|
|
],
|
|
|
|
|
|
|
|
then=1,
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
output_field=models.IntegerField(),
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
).filter(number_validated=True, shift_count__gte=1)
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
Message.objects.bulk_create(
|
|
|
|
|
|
|
|
(
|
|
|
|
|
|
|
|
Message(
|
|
|
|
|
|
|
|
text=form.cleaned_data["message"].replace(
|
|
|
|
|
|
|
|
"$token",
|
|
|
|
|
|
|
|
f"https://kontakt.rocks{helper.logintoken_set.first().get_absolute_url()}",
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
to=helper,
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
for helper in helpers
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
messages.add_message(
|
|
|
|
|
|
|
|
request, messages.SUCCESS, "Massen-Nachricht erfolgreich versendet"
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
except:
|
|
|
|
|
|
|
|
messages.add_message(
|
|
|
|
|
|
|
|
request,
|
|
|
|
|
|
|
|
messages.ERROR,
|
|
|
|
|
|
|
|
"Fehler beim Versenden der Massen-Nachricht",
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context = {
|
|
|
|
|
|
|
|
"form": form,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return render(request, "bulk_message.html", context)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class HelperDetail(LoginRequiredMixin, DetailView):
|
|
|
|
class HelperDetail(LoginRequiredMixin, DetailView):
|
|
|
|
template_name = "helper_detail.html"
|
|
|
|
template_name = "helper_detail.html"
|
|
|
|
model = Helper
|
|
|
|
model = Helper
|
|
|
|