Coverage for website/registrations/emails.py: 100.00%
32 statements
« prev ^ index » next coverage.py v7.6.7, created at 2025-08-14 10:31 +0000
« prev ^ index » next coverage.py v7.6.7, created at 2025-08-14 10:31 +0000
1"""The emails defined by the registrations package."""
3from django.conf import settings
4from django.template.defaultfilters import floatformat
5from django.urls import reverse
7from registrations.models import Registration, Renewal
8from utils.snippets import send_email
11def send_registration_email_confirmation(registration: Registration) -> None:
12 """Send the email confirmation message.
14 :param registration: the registration entry
15 """
16 send_email(
17 to=[registration.email],
18 subject="Confirm email address",
19 txt_template="registrations/email/registration_confirm_mail.txt",
20 html_template="registrations/email/registration_confirm_mail.html",
21 context={
22 "name": registration.get_full_name(),
23 "confirm_link": (
24 settings.BASE_URL
25 + reverse("registrations:confirm-email", args=[registration.pk])
26 ),
27 },
28 )
31def send_registration_accepted_message(registration: Registration) -> None:
32 """Send the registration acceptance email.
34 :param registration: the registration entry
35 """
36 send_email(
37 to=[registration.email],
38 subject="Registration accepted",
39 txt_template="registrations/email/registration_accepted.txt",
40 html_template="registrations/email/registration_accepted.html",
41 context={
42 "name": registration.get_full_name(),
43 "fees": floatformat(registration.contribution, 2),
44 },
45 )
48def send_registration_rejected_message(registration: Registration) -> None:
49 """Send the registration rejection email.
51 :param registration: the registration entry
52 """
53 send_email(
54 to=[registration.email],
55 subject="Registration rejected",
56 txt_template="registrations/email/registration_rejected.txt",
57 html_template="registrations/email/registration_rejected.html",
58 context={"name": registration.get_full_name()},
59 )
62def send_new_registration_board_message(registration: Registration) -> None:
63 """Send a notification to the board about a new registration.
65 :param registration: the registration entry
66 """
67 send_email(
68 to=[settings.BOARD_NOTIFICATION_ADDRESS],
69 subject="New registration",
70 txt_template="registrations/email/registration_board.txt",
71 html_template="registrations/email/registration_board.html",
72 context={
73 "name": registration.get_full_name(),
74 "url": (
75 settings.BASE_URL
76 + reverse(
77 "admin:registrations_registration_change", args=[registration.pk]
78 )
79 ),
80 },
81 )
84def send_renewal_accepted_message(renewal: Renewal) -> None:
85 """Send the renewal acceptation email.
87 :param renewal: the renewal entry
88 """
89 send_email(
90 to=[renewal.member.email],
91 subject="Renewal accepted",
92 txt_template="registrations/email/renewal_accepted.txt",
93 html_template="registrations/email/renewal_accepted.html",
94 context={
95 "name": renewal.member.get_full_name(),
96 "fees": floatformat(renewal.contribution, 2),
97 "thalia_pay_enabled": settings.THALIA_PAY_ENABLED_PAYMENT_METHOD,
98 "url": (
99 settings.BASE_URL
100 + reverse(
101 "registrations:renew",
102 )
103 ),
104 },
105 )
108def send_renewal_rejected_message(renewal: Renewal) -> None:
109 """Send the renewal rejection email.
111 :param renewal: the renewal entry
112 """
113 send_email(
114 to=[renewal.member.email],
115 subject="Renewal rejected",
116 txt_template="registrations/email/renewal_rejected.txt",
117 html_template="registrations/email/renewal_rejected.html",
118 context={"name": renewal.member.get_full_name()},
119 )
122def send_renewal_complete_message(renewal: Renewal) -> None:
123 """Send the email completing the renewal.
125 :param renewal: the renewal entry
126 """
127 send_email(
128 to=[renewal.member.email],
129 subject="Renewal successful",
130 txt_template="registrations/email/renewal_complete.txt",
131 html_template="registrations/email/renewal_complete.html",
132 context={"name": renewal.member.get_full_name()},
133 )
136def send_new_renewal_board_message(renewal: Renewal) -> None:
137 """Send a notification to the board about a new renewal.
139 :param renewal: the renewal entry
140 """
141 send_email(
142 to=[settings.BOARD_NOTIFICATION_ADDRESS],
143 subject="New renewal",
144 txt_template="registrations/email/renewal_board.txt",
145 html_template="registrations/email/renewal_board.html",
146 context={
147 "name": renewal.member.get_full_name(),
148 "url": (
149 settings.BASE_URL
150 + reverse("admin:registrations_renewal_change", args=[renewal.pk])
151 ),
152 },
153 )
156def send_references_information_message(entry: Registration | Renewal) -> None:
157 """Send a notification to the user with information about references.
159 These are required for benefactors who have not been a Thalia member
160 and do not work for iCIS
162 :param entry: the registration or renewal entry
163 """
164 if type(entry).__name__ == "Registration":
165 email = entry.email
166 name = entry.get_full_name()
167 else:
168 email = entry.member.email
169 name = entry.member.get_full_name()
171 send_email(
172 to=[email],
173 subject="Information about references",
174 txt_template="registrations/email/references_information.txt",
175 html_template="registrations/email/references_information.html",
176 context={
177 "name": name,
178 "reference_link": (
179 settings.BASE_URL + reverse("registrations:reference", args=[entry.pk])
180 ),
181 },
182 )
185def send_reminder_open_registration(registration: Registration) -> None:
186 """Send a notification to the board that a registration has been open for more than one month.
188 :param registration: the registration entry
189 """
190 send_email(
191 to=[settings.BOARD_NOTIFICATION_ADDRESS],
192 subject="Open registration for more than one month",
193 txt_template="registrations/email/reminder_open_registration.txt",
194 html_template="registrations/email/reminder_open_registration.html",
195 context={
196 "name": registration.get_full_name(),
197 "created_at": registration.created_at,
198 },
199 )
202def send_reminder_open_renewal(renewal: Renewal) -> None:
203 """Send a notification to the board that a renewal has been open for more than one month.
205 :param renewal: the renewal entry
206 """
207 send_email(
208 to=[settings.BOARD_NOTIFICATION_ADDRESS],
209 subject="Open renewal for more than one month",
210 txt_template="registrations/email/reminder_open_renewal.txt",
211 html_template="registrations/email/reminder_open_renewal.html",
212 context={
213 "name": renewal.member.get_full_name(),
214 "created_at": renewal.created_at,
215 },
216 )