14
14
Registration ,
15
15
ConfirmationToken ,
16
16
BadgeIds ,
17
+ Event ,
18
+ User ,
17
19
)
18
20
from collectives .models .auth import ConfirmationTokenType , TokenEmailStatus
19
21
from collectives .utils import mail
@@ -51,19 +53,24 @@ def send_new_event_notification(event):
51
53
current_app .logger .error (f"Mailer error: { err } " )
52
54
53
55
54
- def send_unregister_notification (event , user ):
56
+ def send_unregister_notification (event : Event , user : User , reason : str ):
55
57
"""Send a notification to leaders when a user unregisters from an event
56
58
57
59
:param event: Event on which user unregisters.
58
- :type event: :py:class:`collectives.modes.event.Event`
59
60
:param user: User who unregisters.
60
- :type user: :py:class:`collectives.models.user.User`
61
+ :param reason: Use-provided reason for unregistering
61
62
"""
62
63
try :
63
64
leader_emails = [l .mail for l in event .leaders ]
64
- message = Configuration .SELF_UNREGISTER_MESSAGE .format (
65
+ reason = (
66
+ f"Justification fournie pour la désinscription : \n { reason } "
67
+ if reason
68
+ else ""
69
+ )
70
+ message = Configuration .SELF_UNREGISTER_MESSAGE_v2 .format (
65
71
user_name = user .full_name (),
66
72
event_title = event .title ,
73
+ reason = reason ,
67
74
link = url_for (
68
75
"event.view_event" ,
69
76
event_id = event .id ,
@@ -139,18 +146,16 @@ def has_succeed():
139
146
db .session .add (token_copy )
140
147
db .session .commit ()
141
148
142
- # Check if local dev, so that email is not sent
143
- # and token validation link is displayed in flash popup
144
- config = current_app .config
145
- if not config ["EXTRANET_DISABLE" ]:
146
- mail .send_mail (
147
- email = email ,
148
- subject = f"{ reason .capitalize ()} de compte Collectives" ,
149
- message = message ,
150
- error_action = has_failed ,
151
- success_action = has_succeed ,
152
- )
153
- else :
149
+ mail .send_mail (
150
+ email = email ,
151
+ subject = f"{ reason .capitalize ()} de compte Collectives" ,
152
+ message = message ,
153
+ error_action = has_failed ,
154
+ success_action = has_succeed ,
155
+ )
156
+
157
+ # Check if local dev, then token validation link is displayed in flash popup
158
+ if current_app .config ["EXTRANET_DISABLE" ]:
154
159
has_succeed ()
155
160
url = url_for (
156
161
"auth.process_confirmation" , token_uuid = token .uuid , _external = True
@@ -161,19 +166,23 @@ def has_succeed():
161
166
flash (Markup (line ))
162
167
163
168
164
- def send_reject_subscription_notification (rejector_name , event , rejected_user_email ):
169
+ def send_reject_subscription_notification (
170
+ rejector_name : str , event : Event , rejected_user_email : str , reason : str
171
+ ):
165
172
"""Send a notification to user whom registration has been rejected
166
173
167
- :param string rejector_name: User name who rejects the subscription.
174
+ :param rejector_name: User name who rejects the subscription.
168
175
:param event: Event the registraton is rejected on.
169
- :type event: :py:class:`collectives.modes.event.Event`
170
- :param string rejected_user_email: User email for who registraton is rejected.
176
+ :param rejected_user_email: User email for who registraton is rejected.
177
+ :param reason: Reason for the rejection
171
178
"""
172
179
try :
173
- message = Configuration .REJECTED_REGISTRATION_MESSAGE .format (
180
+ reason = f"Justification du refus : \n { reason } " if reason else ""
181
+ message = Configuration .REJECTED_REGISTRATION_MESSAGE_v2 .format (
174
182
rejector_name = rejector_name ,
175
183
event_title = event .title ,
176
184
event_date = format_date (event .start ),
185
+ reason = reason ,
177
186
link = url_for (
178
187
"event.view_event" ,
179
188
event_id = event .id ,
@@ -242,32 +251,30 @@ def send_update_waiting_list_notification(
242
251
end_of_grace = current_time () + timedelta (
243
252
hours = Configuration .UNREGISTRATION_GRACE_PERIOD + 1
244
253
)
254
+
245
255
if registration .is_in_late_unregistration_period (end_of_grace ):
246
- message = (
247
- Configuration .ACTIVATED_REGISTRATION_UPCOMING_EVENT_MESSAGE .format (
248
- event_title = registration .event .title ,
249
- event_date = format_date (registration .event .start ),
256
+ unregistration_text = (
257
+ Configuration .ACTIVATED_REGISTRATION_UPCOMING_EVENT_WARNING .format (
250
258
grace_period = Configuration .UNREGISTRATION_GRACE_PERIOD ,
251
- link = url_for (
252
- "event.view_event" ,
253
- event_id = registration .event .id ,
254
- name = slugify (registration .event .title ),
255
- _external = True ,
256
- ),
257
259
)
258
260
)
259
261
else :
260
- message = Configuration .ACTIVATED_REGISTRATION_MESSAGE .format (
261
- event_title = registration .event .title ,
262
- event_date = format_date (registration .event .start ),
263
- link = url_for (
264
- "event.view_event" ,
265
- event_id = registration .event .id ,
266
- name = slugify (registration .event .title ),
267
- _external = True ,
268
- ),
262
+ unregistration_text = (
263
+ Configuration .ACTIVATED_REGISTRATION_STANDARD_EVENT_MESSAGE
269
264
)
270
265
266
+ message = Configuration .ACTIVATED_REGISTRATION_MESSAGE_v2 .format (
267
+ event_title = registration .event .title ,
268
+ event_date = format_date (registration .event .start ),
269
+ unregistration_text = unregistration_text ,
270
+ link = url_for (
271
+ "event.view_event" ,
272
+ event_id = registration .event .id ,
273
+ name = slugify (registration .event .title ),
274
+ _external = True ,
275
+ ),
276
+ )
277
+
271
278
if deleted_registrations :
272
279
event_titles = "\n " .join (
273
280
f" - { reg .event .title } " for reg in deleted_registrations
0 commit comments