1111from acm import error_codes as EC
1212
1313from .models import Competition , CompetitionFieldConfig , TeamRequest , TeamMember , FieldRequirement
14- from notification .services import send_status_change_email
14+ from notification .services import send_status_change_email , send_email_with_custom_template
1515
1616User = get_user_model ()
1717
@@ -133,20 +133,22 @@ def submit_team_request(
133133 approval_token_expires_at = expires ,
134134 )
135135 # email tokenized approval link
136- send_status_change_email (
136+ send_email_with_custom_template (
137137 to = p .get ("email" , "" ),
138138 status_code = "COMPETITION_MEMBER_APPROVAL" ,
139+ template = "COMPETITION_MEMBER_APPROVAL" ,
139140 extra = {
140141 "competition" : competition .name ,
141142 "team_name" : team_name or "" ,
142- "action_link " : f"/api/competitions/approve ?rid={ tr .id } &token={ token } " ,
143+ "approval_link " : f"{ settings . COMPETITION_APPROVAL_REDIRECT_URL } ?rid={ tr .id } &token={ token } " ,
143144 },
144145 )
145146
146147 # notify submitter about submission
147- send_status_change_email (
148+ send_email_with_custom_template (
148149 to = submitter .email ,
149150 status_code = "COMPETITION_REQUEST_SUBMITTED" ,
151+ template = "COMPETITION_REQUEST_SUBMITTED" ,
150152 extra = {"competition" : competition .name , "team_name" : team_name or "" },
151153 )
152154
@@ -190,19 +192,21 @@ def approve_or_reject_member(*, request_id: int, token: str, accept: bool) -> Te
190192 tr .status = TeamRequest .Status .REJECTED
191193 tr .save (update_fields = ["status" ])
192194 # notify submitter
193- send_status_change_email (
195+ send_email_with_custom_template (
194196 to = tr .submitter .email ,
195197 status_code = "COMPETITION_REQUEST_REJECTED" ,
198+ template = "COMPETITION_REQUEST_REJECTED" ,
196199 extra = {"competition" : tr .competition .name },
197200 )
198201 elif not tr .members .filter (approval_status = TeamMember .ApprovalStatus .PENDING ).exists ():
199202 # all approved
200203 if tr .competition .requires_backoffice_approval :
201204 tr .status = TeamRequest .Status .PENDING_INVESTIGATION
202205 tr .save (update_fields = ["status" ])
203- send_status_change_email (
206+ send_email_with_custom_template (
204207 to = tr .submitter .email ,
205208 status_code = "COMPETITION_REQUEST_PENDING_INVESTIGATION" ,
209+ template = "COMPETITION_REQUEST_PENDING_INVESTIGATION" ,
206210 extra = {"competition" : tr .competition .name },
207211 )
208212 else :
@@ -225,9 +229,10 @@ def approve_or_reject_member(*, request_id: int, token: str, accept: bool) -> Te
225229 tr .payment_link = result .url
226230 tr .status = TeamRequest .Status .PENDING_PAYMENT
227231 tr .save (update_fields = ["payment_link" , "status" ])
228- send_status_change_email (
232+ send_email_with_custom_template (
229233 to = tr .submitter .email ,
230234 status_code = "COMPETITION_REQUEST_PENDING_PAYMENT" ,
235+ template = "COMPETITION_REQUEST_PENDING_PAYMENT" ,
231236 extra = {"link" : tr .payment_link },
232237 )
233238
@@ -296,9 +301,10 @@ def backoffice_approve_request(tr: TeamRequest) -> TeamRequest:
296301 tr .payment_link = result .url
297302 tr .status = TeamRequest .Status .PENDING_PAYMENT
298303 tr .save (update_fields = ["payment_link" , "status" ])
299- send_status_change_email (
304+ send_email_with_custom_template (
300305 to = tr .submitter .email ,
301306 status_code = "COMPETITION_REQUEST_PENDING_PAYMENT" ,
307+ template = "COMPETITION_REQUEST_PENDING_PAYMENT" ,
302308 extra = {"link" : tr .payment_link },
303309 )
304310 return tr
@@ -316,9 +322,10 @@ def backoffice_reject_request(tr: TeamRequest, reason: str) -> TeamRequest:
316322 tr .save (update_fields = ["status" ])
317323 # notify all members
318324 for m in tr .members .all ():
319- send_status_change_email (
325+ send_email_with_custom_template (
320326 to = m .email ,
321327 status_code = "COMPETITION_REQUEST_REJECTED" ,
328+ template = "COMPETITION_REQUEST_REJECTED" ,
322329 extra = {"competition" : tr .competition .name , "reason" : reason },
323330 )
324331 return tr
@@ -329,9 +336,10 @@ def mark_payment_final(tr: TeamRequest) -> TeamRequest:
329336 tr .status = TeamRequest .Status .FINAL
330337 tr .save (update_fields = ["status" ])
331338 for m in tr .members .all ():
332- send_status_change_email (
339+ send_email_with_custom_template (
333340 to = m .email ,
334341 status_code = "COMPETITION_REQUEST_FINAL" ,
342+ template = "COMPETITION_REQUEST_FINAL" ,
335343 extra = {"competition" : tr .competition .name },
336344 )
337345 return tr
@@ -341,9 +349,10 @@ def mark_payment_final(tr: TeamRequest) -> TeamRequest:
341349def mark_payment_rejected (tr : TeamRequest ) -> TeamRequest :
342350 tr .status = TeamRequest .Status .PAYMENT_REJECTED
343351 tr .save (update_fields = ["status" ])
344- send_status_change_email (
352+ send_email_with_custom_template (
345353 to = tr .submitter .email ,
346354 status_code = "COMPETITION_PAYMENT_REJECTED" ,
355+ template = "COMPETITION_PAYMENT_REJECTED" ,
347356 extra = {"competition" : tr .competition .name },
348357 )
349358 return tr
0 commit comments