Merge separate bulk message views
This commit is contained in:
parent
7db3e68260
commit
440e128bcc
|
@ -19,3 +19,6 @@ class BulkMessage(forms.Form):
|
||||||
message = forms.CharField(
|
message = forms.CharField(
|
||||||
label="Nachricht", widget=forms.Textarea(attrs={"class": "textarea"})
|
label="Nachricht", widget=forms.Textarea(attrs={"class": "textarea"})
|
||||||
)
|
)
|
||||||
|
checked_in_only = forms.BooleanField(
|
||||||
|
label="Nur an Helfer*innen mit mindestens einem Check-in senden", required=False
|
||||||
|
)
|
||||||
|
|
|
@ -7,10 +7,16 @@
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
{% for field in form %}
|
{% for field in form %}
|
||||||
<div class="field">
|
<div class="field">
|
||||||
|
{% if field.widget_type == 'checkbox' %}
|
||||||
|
<div class="control">
|
||||||
|
<label class="checkbox" for="{{ field.id_for_label }}">{{ field }} {{ field.label }}</label>
|
||||||
|
</div>
|
||||||
|
{% else %}
|
||||||
<label class="label" for="{{ field.id_for_label }}">{{ field.label }}</label>
|
<label class="label" for="{{ field.id_for_label }}">{{ field.label }}</label>
|
||||||
<div class="control">
|
<div class="control">
|
||||||
{{ field }}
|
{{ field }}
|
||||||
</div>
|
</div>
|
||||||
|
{% endif %}
|
||||||
{% for error in field.errors %}
|
{% for error in field.errors %}
|
||||||
<p class="help is-danger">{{ error }}</p>
|
<p class="help is-danger">{{ error }}</p>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
|
@ -11,7 +11,6 @@ urlpatterns = [
|
||||||
path("shift/<int:pk>", views.shift_detail, name="shift"),
|
path("shift/<int:pk>", views.shift_detail, name="shift"),
|
||||||
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("message2/", views.bulk_message_helped, name="bulk_message_helped"),
|
|
||||||
path("checkin/<int:pk>", views.checkin, name="checkin"),
|
path("checkin/<int:pk>", views.checkin, name="checkin"),
|
||||||
path("remove_helper/<int:pk>", views.delete_shiftregistration, name="unregister"),
|
path("remove_helper/<int:pk>", views.delete_shiftregistration, name="unregister"),
|
||||||
]
|
]
|
||||||
|
|
|
@ -89,55 +89,22 @@ def bulk_message(request):
|
||||||
if request.method == "POST":
|
if request.method == "POST":
|
||||||
form = BulkMessage(request.POST)
|
form = BulkMessage(request.POST)
|
||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
try:
|
helpers = Helper.objects.filter(number_validated=True)
|
||||||
Message.objects.bulk_create(
|
if form.cleaned_data["checked_in_only"]:
|
||||||
(
|
helpers = Helper.objects.annotate(
|
||||||
Message(
|
shift_count=Count(
|
||||||
text=form.cleaned_data["message"].replace(
|
Case(
|
||||||
"$token",
|
When(
|
||||||
f"https://kontakt.rocks{helper.logintoken_set.first().get_absolute_url()}",
|
shiftregistration__state__in=[
|
||||||
|
ShiftRegistration.RegState.CHECKED_IN,
|
||||||
|
],
|
||||||
|
then=1,
|
||||||
),
|
),
|
||||||
to=helper,
|
output_field=models.IntegerField(),
|
||||||
)
|
)
|
||||||
for helper in Helper.objects.filter(number_validated=True)
|
|
||||||
)
|
)
|
||||||
)
|
).filter(number_validated=True, shift_count__gte=1)
|
||||||
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)
|
|
||||||
|
|
||||||
|
|
||||||
@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:
|
try:
|
||||||
Message.objects.bulk_create(
|
Message.objects.bulk_create(
|
||||||
(
|
(
|
||||||
|
|
Loading…
Reference in New Issue