|
|
|
@ -89,55 +89,22 @@ def bulk_message(request):
|
|
|
|
|
if request.method == "POST":
|
|
|
|
|
form = BulkMessage(request.POST)
|
|
|
|
|
if form.is_valid():
|
|
|
|
|
try:
|
|
|
|
|
Message.objects.bulk_create(
|
|
|
|
|
(
|
|
|
|
|
Message(
|
|
|
|
|
text=form.cleaned_data["message"].replace(
|
|
|
|
|
"$token",
|
|
|
|
|
f"https://kontakt.rocks{helper.logintoken_set.first().get_absolute_url()}",
|
|
|
|
|
helpers = Helper.objects.filter(number_validated=True)
|
|
|
|
|
if form.cleaned_data["checked_in_only"]:
|
|
|
|
|
helpers = Helper.objects.annotate(
|
|
|
|
|
shift_count=Count(
|
|
|
|
|
Case(
|
|
|
|
|
When(
|
|
|
|
|
shiftregistration__state__in=[
|
|
|
|
|
ShiftRegistration.RegState.CHECKED_IN,
|
|
|
|
|
],
|
|
|
|
|
then=1,
|
|
|
|
|
),
|
|
|
|
|
to=helper,
|
|
|
|
|
output_field=models.IntegerField(),
|
|
|
|
|
)
|
|
|
|
|
for helper in Helper.objects.filter(number_validated=True)
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
|
|
).filter(number_validated=True, shift_count__gte=1)
|
|
|
|
|
|
|
|
|
|
@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(
|
|
|
|
|
(
|
|
|
|
|