add hold function to OutgoingEmail, set hold=True to delay sending emails
This commit is contained in:
parent
daefd62f96
commit
bd36e70bc3
|
@ -74,6 +74,7 @@ def add_outgoing_email(
|
|||
sender="BornHack <info@bornhack.dk>",
|
||||
attachment=None,
|
||||
attachment_filename="",
|
||||
hold=False,
|
||||
):
|
||||
""" adds an email to the outgoing queue
|
||||
recipients is a list of to recipients
|
||||
|
@ -104,6 +105,7 @@ def add_outgoing_email(
|
|||
to_recipients=to_recipients,
|
||||
cc_recipients=cc_recipients,
|
||||
bcc_recipients=bcc_recipients,
|
||||
hold=hold,
|
||||
)
|
||||
|
||||
if attachment:
|
||||
|
|
109
src/utils/migrations/0005_auto_20200622_1544.py
Normal file
109
src/utils/migrations/0005_auto_20200622_1544.py
Normal file
|
@ -0,0 +1,109 @@
|
|||
# Generated by Django 3.0.3 on 2020-06-22 13:44
|
||||
|
||||
import django.contrib.postgres.fields
|
||||
import django.db.models.deletion
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("teams", "0052_team_permission_set"),
|
||||
("utils", "0004_uuidtaggeditem"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name="outgoingemail",
|
||||
name="hold",
|
||||
field=models.BooleanField(
|
||||
default=False,
|
||||
help_text="Hold (do not send) this email. Uncheck to send.",
|
||||
),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name="outgoingemail",
|
||||
name="responsible_team",
|
||||
field=models.ForeignKey(
|
||||
blank=True,
|
||||
help_text="The Team responsible for this email.",
|
||||
null=True,
|
||||
on_delete=django.db.models.deletion.PROTECT,
|
||||
to="teams.Team",
|
||||
),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name="outgoingemail",
|
||||
name="attachment",
|
||||
field=models.FileField(
|
||||
blank=True,
|
||||
help_text="The attachment for this email. Optional.",
|
||||
upload_to="",
|
||||
),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name="outgoingemail",
|
||||
name="bcc_recipients",
|
||||
field=django.contrib.postgres.fields.ArrayField(
|
||||
base_field=models.CharField(blank=True, max_length=500),
|
||||
blank=True,
|
||||
help_text="The Bcc: recipients",
|
||||
null=True,
|
||||
size=None,
|
||||
),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name="outgoingemail",
|
||||
name="cc_recipients",
|
||||
field=django.contrib.postgres.fields.ArrayField(
|
||||
base_field=models.CharField(blank=True, max_length=500),
|
||||
blank=True,
|
||||
help_text="The Cc: recipients",
|
||||
null=True,
|
||||
size=None,
|
||||
),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name="outgoingemail",
|
||||
name="html_template",
|
||||
field=models.TextField(
|
||||
blank=True, help_text="The HTML body of the email (optional)."
|
||||
),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name="outgoingemail",
|
||||
name="processed",
|
||||
field=models.BooleanField(
|
||||
default=False,
|
||||
help_text="Unchecked before the email is sent, checked after the email has been sent.",
|
||||
),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name="outgoingemail",
|
||||
name="sender",
|
||||
field=models.CharField(help_text="The email sender.", max_length=500),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name="outgoingemail",
|
||||
name="subject",
|
||||
field=models.CharField(
|
||||
help_text="The subject of the e-mail", max_length=500
|
||||
),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name="outgoingemail",
|
||||
name="text_template",
|
||||
field=models.TextField(help_text="The plaintext body of the email."),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name="outgoingemail",
|
||||
name="to_recipients",
|
||||
field=django.contrib.postgres.fields.ArrayField(
|
||||
base_field=models.CharField(blank=True, max_length=500),
|
||||
blank=True,
|
||||
help_text="The To: recipients",
|
||||
null=True,
|
||||
size=None,
|
||||
),
|
||||
),
|
||||
]
|
|
@ -82,21 +82,49 @@ class CampRelatedModel(CreatedUpdatedModel):
|
|||
|
||||
|
||||
class OutgoingEmail(CreatedUpdatedModel):
|
||||
subject = models.CharField(max_length=500)
|
||||
text_template = models.TextField()
|
||||
html_template = models.TextField(blank=True)
|
||||
sender = models.CharField(max_length=500)
|
||||
"""The OutgoingEmail model contains all system emails, both unsent and sent."""
|
||||
|
||||
subject = models.CharField(max_length=500, help_text="The subject of the e-mail")
|
||||
text_template = models.TextField(help_text="The plaintext body of the email.")
|
||||
html_template = models.TextField(
|
||||
blank=True, help_text="The HTML body of the email (optional)."
|
||||
)
|
||||
sender = models.CharField(max_length=500, help_text="The email sender.")
|
||||
to_recipients = ArrayField(
|
||||
models.CharField(max_length=500, blank=True), null=True, blank=True
|
||||
models.CharField(max_length=500, blank=True),
|
||||
null=True,
|
||||
blank=True,
|
||||
help_text="The To: recipients",
|
||||
)
|
||||
cc_recipients = ArrayField(
|
||||
models.CharField(max_length=500, blank=True), null=True, blank=True
|
||||
models.CharField(max_length=500, blank=True),
|
||||
null=True,
|
||||
blank=True,
|
||||
help_text="The Cc: recipients",
|
||||
)
|
||||
bcc_recipients = ArrayField(
|
||||
models.CharField(max_length=500, blank=True), null=True, blank=True
|
||||
models.CharField(max_length=500, blank=True),
|
||||
null=True,
|
||||
blank=True,
|
||||
help_text="The Bcc: recipients",
|
||||
)
|
||||
attachment = models.FileField(
|
||||
blank=True, help_text="The attachment for this email. Optional."
|
||||
)
|
||||
processed = models.BooleanField(
|
||||
default=False,
|
||||
help_text="Unchecked before the email is sent, checked after the email has been sent.",
|
||||
)
|
||||
hold = models.BooleanField(
|
||||
default=False, help_text="Hold (do not send) this email. Uncheck to send."
|
||||
)
|
||||
responsible_team = models.ForeignKey(
|
||||
"teams.Team",
|
||||
null=True,
|
||||
blank=True,
|
||||
on_delete=models.PROTECT,
|
||||
help_text="The Team responsible for this email.",
|
||||
)
|
||||
attachment = models.FileField(blank=True)
|
||||
processed = models.BooleanField(default=False)
|
||||
|
||||
def __str__(self):
|
||||
return "OutgoingEmail Object id: {} ".format(self.id)
|
||||
|
|
|
@ -12,7 +12,7 @@ def do_work():
|
|||
The outgoing email worker sends emails added to the OutgoingEmail
|
||||
queue.
|
||||
"""
|
||||
not_processed_email = OutgoingEmail.objects.filter(processed=False)
|
||||
not_processed_email = OutgoingEmail.objects.filter(processed=False, hold=False)
|
||||
|
||||
if len(not_processed_email) > 0:
|
||||
logger.debug("about to process {} emails".format(len(not_processed_email)))
|
||||
|
@ -38,6 +38,6 @@ def do_work():
|
|||
if mail_send_success:
|
||||
email.processed = True
|
||||
email.save()
|
||||
logger.debug("successfully sent {}".format(email))
|
||||
logger.debug("Successfully sent {}".format(email))
|
||||
else:
|
||||
logger.error("unable to sent {}".format(email))
|
||||
logger.error("Unable to send {}".format(email))
|
||||
|
|
Loading…
Reference in a new issue