Skip to content

Commit 4f330c1

Browse files
committed
draft email
1 parent 8ea23ff commit 4f330c1

1 file changed

Lines changed: 32 additions & 4 deletions

File tree

backend/notifications/models.py

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,18 +211,17 @@ def render(
211211
placeholders=placeholders,
212212
)
213213

214-
def send_email(
214+
def _prepare_email(
215215
self,
216216
*,
217217
recipient: User | None = None,
218218
recipient_email: str | None = None,
219219
placeholders: dict = None,
220+
status: "SentEmail.Status" | None = None,
220221
):
221222
if not recipient and not recipient_email:
222223
raise ValueError("Either recipient or recipient_email must be provided")
223224

224-
from notifications.tasks import send_pending_email
225-
226225
recipient_email = recipient_email or recipient.email
227226

228227
placeholders = placeholders or {}
@@ -236,7 +235,8 @@ def send_email(
236235
or settings.DEFAULT_FROM_EMAIL
237236
)
238237

239-
sent_email = SentEmail.objects.create(
238+
return SentEmail.objects.create(
239+
status=status or SentEmail.Status.draft,
240240
email_template=self,
241241
conference=self.conference,
242242
from_email=from_email,
@@ -252,6 +252,34 @@ def send_email(
252252
bcc_addresses=self.bcc_addresses,
253253
)
254254

255+
def draft_email(
256+
self,
257+
*,
258+
recipient: User | None = None,
259+
recipient_email: str | None = None,
260+
placeholders: dict = None,
261+
):
262+
return self._prepare_email(
263+
recipient=recipient,
264+
recipient_email=recipient_email,
265+
placeholders=placeholders,
266+
)
267+
268+
def send_email(
269+
self,
270+
*,
271+
recipient: User | None = None,
272+
recipient_email: str | None = None,
273+
placeholders: dict = None,
274+
):
275+
from notifications.tasks import send_pending_email
276+
277+
sent_email = self._prepare_email(
278+
status=SentEmail.Status.pending,
279+
recipient=recipient,
280+
recipient_email=recipient_email,
281+
placeholders=placeholders,
282+
)
255283
transaction.on_commit(lambda: send_pending_email.delay(sent_email.id))
256284

257285
@property

0 commit comments

Comments
 (0)