From 6a2ec9bff1c4931d97f7b696be8c109a1f10d76e Mon Sep 17 00:00:00 2001 From: mhewel <58829786+mhewel@users.noreply.github.com> Date: Tue, 22 Aug 2023 14:12:13 +0200 Subject: [PATCH] =?UTF-8?q?Send=20email=20for=20invitationer,=20nu=20ogs?= =?UTF-8?q?=C3=A5=20med=20ekstra=20tekst?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- members/admin/admin_actions.py | 43 ++++++++++++++++++- members/models/activityinvite.py | 15 ------- .../admin/invite_many_to_activity.html | 16 ++++++- 3 files changed, 56 insertions(+), 18 deletions(-) diff --git a/members/admin/admin_actions.py b/members/admin/admin_actions.py index 1afc6ae6..cc1a4885 100644 --- a/members/admin/admin_actions.py +++ b/members/admin/admin_actions.py @@ -10,6 +10,8 @@ from django.utils.safestring import mark_safe from django.utils.html import escape from django.shortcuts import render +import members.models.emailtemplate +import members.models.waitinglist from members.models import ( Activity, @@ -23,6 +25,10 @@ class AdminActions(admin.ModelAdmin): def invite_many_to_activity_action(modelAdmin, request, queryset): + template = members.models.emailtemplate.EmailTemplate.objects.get( + idname="ACT_INVITE" + ) + # Get list of available departments if request.user.is_superuser or request.user.has_perm( "members.view_all_persons" @@ -60,6 +66,9 @@ class MassInvitationForm(forms.Form): widget=AdminDateWidget(), initial=timezone.now() + timedelta(days=30 * 3), ) + email_text = forms.CharField( + label="Email ekstra info", widget=forms.Textarea + ) # Lookup all the selected persons - to show confirmation list # Check if it's called from Waiting List @@ -180,15 +189,45 @@ class MassInvitationForm(forms.Form): "expire" ], ) + + email_info = mass_invitation_form.cleaned_data[ + "email_text" + ] + + mail_context = { + "activity": activity, + "activity_invite": invitation, + "person": current_person, + "family": current_person.family, + "email_extra_info": email_info, + } invitation.save() + if current_person.email and ( + current_person.email + != current_person.family.email + ): + # If invited has own email, also send to that. + template.makeEmail( + [current_person, current_person.family], + mail_context, + True, + ) + else: + # otherwise use only family + template.makeEmail( + current_person.family, + mail_context, + True, + ) persons_invited.append(current_person.name) - except Exception: + except Exception as E: messages.error( request, "Fejl - ingen personer blev inviteret! Der var problemer med " + (invitation.person.name if invitation else "(n/a)") - + ". Vær sikker på personen ikke allerede er inviteret og opfylder alderskravet.", + + ". Vær sikker på personen ikke allerede er inviteret og opfylder alderskravet." + + f"{E=}", ) return diff --git a/members/models/activityinvite.py b/members/models/activityinvite.py index 643affd9..13d197ba 100644 --- a/members/models/activityinvite.py +++ b/members/models/activityinvite.py @@ -45,21 +45,6 @@ def clean(self): def save(self, *args, **kwargs): if not self.id: super(ActivityInvite, self).save(*args, **kwargs) - template = members.models.emailtemplate.EmailTemplate.objects.get( - idname="ACT_INVITE" - ) - context = { - "activity": self.activity, - "activity_invite": self, - "person": self.person, - "family": self.person.family, - } - if self.person.email and (self.person.email != self.person.family.email): - # If invited has own email, also send to that. - template.makeEmail([self.person, self.person.family], context) - else: - # otherwise use only family - template.makeEmail(self.person.family, context) # remove from department waiting list if self.activity.is_season(): members.models.waitinglist.WaitingList.objects.filter( diff --git a/members/templates/admin/invite_many_to_activity.html b/members/templates/admin/invite_many_to_activity.html index a4eba9c9..0b5fcea1 100644 --- a/members/templates/admin/invite_many_to_activity.html +++ b/members/templates/admin/invite_many_to_activity.html @@ -32,7 +32,8 @@

Vælg aktivitet

Gennemgå listen og vælg den korrekte afdeling og aktivitet der skal inviteres til.

-

Vælg desuden en udløbsdato for invitationen.

+

Vælg desuden en udløbsdato for invitationen.

+

Skriv noget ekstra tekst

Når du trykker på  INVITER -knappen vil systemet invitere personer, der ikke allerede deltager/er inviteret til aktiviteten samt er indenfor aldersgrænsen når aktiviteten starter. Det endeligt antal inviterede kan derfor afvige fra antallet i listen herunder.

Der sendes en email med en beskrivelse af aktiviteten samt et link til tilmelding!

@@ -51,6 +52,19 @@

Vælg aktivitet

{% endfor %} +

Email template

+
+

Alle personer inviteres og der sendes en email udfra følgende mail template:


+ ID: +
{{ emailtemplate.idname }}

+ Subject: +
{{ emailtemplate.subject }}

+ HTML: +
{{ emailtemplate.body_html }}
+ Text: +
{{ emailtemplate.body_text }}
+
+

Bekræft deltagere

Følgende ({{persons.count}}) personer inviteres: