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(
|
||||
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 %}
|
||||
{% for field in form %}
|
||||
<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>
|
||||
<div class="control">
|
||||
{{ field }}
|
||||
</div>
|
||||
{% endif %}
|
||||
{% for error in field.errors %}
|
||||
<p class="help is-danger">{{ error }}</p>
|
||||
{% endfor %}
|
||||
|
|
|
@ -11,7 +11,6 @@ urlpatterns = [
|
|||
path("shift/<int:pk>", views.shift_detail, name="shift"),
|
||||
path("helper/<int:pk>", views.HelperDetail.as_view(), name="helper"),
|
||||
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("remove_helper/<int:pk>", views.delete_shiftregistration, name="unregister"),
|
||||
]
|
||||
|
|
|
@ -89,42 +89,8 @@ 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()}",
|
||||
),
|
||||
to=helper,
|
||||
)
|
||||
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)
|
||||
|
||||
|
||||
@login_required
|
||||
def bulk_message_helped(request):
|
||||
form = BulkMessage()
|
||||
|
||||
if request.method == "POST":
|
||||
form = BulkMessage(request.POST)
|
||||
if form.is_valid():
|
||||
helpers = Helper.objects.filter(number_validated=True)
|
||||
if form.cleaned_data["checked_in_only"]:
|
||||
helpers = Helper.objects.annotate(
|
||||
shift_count=Count(
|
||||
Case(
|
||||
|
@ -138,6 +104,7 @@ def bulk_message_helped(request):
|
|||
)
|
||||
)
|
||||
).filter(number_validated=True, shift_count__gte=1)
|
||||
|
||||
try:
|
||||
Message.objects.bulk_create(
|
||||
(
|
||||
|
|
Loading…
Reference in New Issue