Skip to content

Commit

Permalink
Send email for invitationer, nu også med ekstra tekst
Browse files Browse the repository at this point in the history
  • Loading branch information
mhewel committed Aug 22, 2023
1 parent 40af154 commit 6a2ec9b
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 18 deletions.
43 changes: 41 additions & 2 deletions members/admin/admin_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
15 changes: 0 additions & 15 deletions members/models/activityinvite.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
16 changes: 15 additions & 1 deletion members/templates/admin/invite_many_to_activity.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
<h2>Vælg aktivitet</h2>
<div class="description">
<p>Gennemgå listen og vælg den korrekte afdeling og aktivitet der skal inviteres til.</p>
<p>Vælg desuden en udløbsdato for invitationen. </p>
<p>Vælg desuden en udløbsdato for invitationen.</p>
<p>Skriv noget ekstra tekst</p>
<p>Når du trykker på <kbd style="background-color:green; color: white;">&nbsp;INVITER&nbsp;</kbd>-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.</p>
<p>Der sendes en email med en beskrivelse af aktiviteten samt et link til tilmelding!</p>
</div>
Expand All @@ -51,6 +52,19 @@ <h2>Vælg aktivitet</h2>
</div>
{% endfor %}

<h2>Email template</h2>
<div class="description">
<p>Alle personer inviteres og der sendes en email udfra følgende mail template:</p><br>
<b>ID: </b>
<text readonly><pre>{{ emailtemplate.idname }}</pre></text><br>
<b>Subject: </b>
<text readonly><pre>{{ emailtemplate.subject }}</pre></text><br>
<b>HTML: </b>
<text readonly><pre>{{ emailtemplate.body_html }}</pre></text>
<b>Text: </b>
<text readonly><pre>{{ emailtemplate.body_text }}</pre></text>
</div>

<h2>Bekræft deltagere</h2>
<div class="description">
<p>Følgende ({{persons.count}}) personer inviteres:</p>
Expand Down

0 comments on commit 6a2ec9b

Please sign in to comment.