use a list for recipients rather than a string

This commit is contained in:
Stephan Telling 2017-05-21 17:23:48 +02:00
parent f986617c64
commit 6a98ee3564
No known key found for this signature in database
GPG key ID: D4892289F36ADA9B
3 changed files with 8 additions and 13 deletions

View file

@ -49,9 +49,7 @@ def send_new_membership_email(membership):
return add_outgoing_email( return add_outgoing_email(
text_template='emails/new_membership_email.txt', text_template='emails/new_membership_email.txt',
html_template='emails/new_membership_email.html', html_template='emails/new_membership_email.html',
recipients=', '.join( recipients=membership.team.responsible,
[resp.email for resp in membership.team.responsible]
),
formatdict=formatdict, formatdict=formatdict,
subject='New membership request for {} at {}'.format( subject='New membership request for {} at {}'.format(
membership.team.name, membership.team.name,

View file

@ -66,22 +66,19 @@ def add_outgoing_email(
attachment_filename='' attachment_filename=''
): ):
""" adds an email to the outgoing queue """ adds an email to the outgoing queue
recipients is a string, if theres multiple emails seperate with a comma recipients is a list of to recipients
""" """
text_template = render_to_string(text_template, formatdict) text_template = render_to_string(text_template, formatdict)
if html_template: if html_template:
html_template = render_to_string(html_template, formatdict) html_template = render_to_string(html_template, formatdict)
if ',' in recipients: if not isinstance(recipients, list):
for recipient in recipients.split(','): recipients = [recipients]
try:
validate_email(recipient.strip()) for recipient in recipients:
except ValidationError:
return False
else:
try: try:
validate_email(recipients) validate_email(recipient)
except ValidationError: except ValidationError:
return False return False

View file

@ -1,4 +1,5 @@
import uuid import uuid
from django.contrib.postgres.fields import ArrayField
from django.core.exceptions import ValidationError from django.core.exceptions import ValidationError
from django.contrib import messages from django.contrib import messages
from django.db import models from django.db import models
@ -74,7 +75,6 @@ class OutgoingEmail(CreatedUpdatedModel):
subject = models.CharField(max_length=500) subject = models.CharField(max_length=500)
text_template = models.TextField() text_template = models.TextField()
html_template = models.TextField(blank=True) html_template = models.TextField(blank=True)
recipient = models.CharField(max_length=500)
sender = models.CharField(max_length=500) sender = models.CharField(max_length=500)
attachment = models.FileField(blank=True) attachment = models.FileField(blank=True)
processed = models.BooleanField(default=False) processed = models.BooleanField(default=False)