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: