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 1/2] =?UTF-8?q?Send=20email=20for=20invitationer,=20nu=20o?= =?UTF-8?q?gs=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 @@
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!
Alle personer inviteres og der sendes en email udfra følgende mail template:
{{ emailtemplate.idname }}
{{ emailtemplate.subject }}
{{ emailtemplate.body_html }}
{{ emailtemplate.body_text }}
Følgende ({{persons.count}}) personer inviteres:
From 645d44ad9c7e08d218d1549f0ce3358b43c4fd4c Mon Sep 17 00:00:00 2001 From: mhewel <58829786+mhewel@users.noreply.github.com> Date: Tue, 29 Aug 2023 14:35:39 +0200 Subject: [PATCH 2/2] =?UTF-8?q?Tilf=C3=B8jede=20email=5Ftext=20til=20test?= =?UTF-8?q?=20case?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- members/tests/test_admin_admin_actions.py | 1 + 1 file changed, 1 insertion(+) diff --git a/members/tests/test_admin_admin_actions.py b/members/tests/test_admin_admin_actions.py index 08a32ff9..7948370e 100644 --- a/members/tests/test_admin_admin_actions.py +++ b/members/tests/test_admin_admin_actions.py @@ -94,6 +94,7 @@ def create_mock_request_object(self): "activity": "1", "department": "1", "expire": datetime.fromisoformat("2023-12-31"), + "email_text": "Lidt ekstra tekst", } request.user = self.user