Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Place email template improvements #120

Merged
merged 8 commits into from
Apr 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions src/sa_api_v2/migrations/0007_auto_20180420_2202.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations


class Migration(migrations.Migration):

dependencies = [
('sa_api_v2', '0006_attachment_type'),
]

operations = [
migrations.RemoveField(
model_name='placeemailtemplate',
name='bcc_email',
),
migrations.AddField(
model_name='placeemailtemplate',
name='bcc_email_1',
field=models.EmailField(default=None, max_length=75, null=True, blank=True),
preserve_default=True,
),
migrations.AddField(
model_name='placeemailtemplate',
name='bcc_email_2',
field=models.EmailField(default=None, max_length=75, null=True, blank=True),
preserve_default=True,
),
migrations.AddField(
model_name='placeemailtemplate',
name='bcc_email_3',
field=models.EmailField(default=None, max_length=75, null=True, blank=True),
preserve_default=True,
),
migrations.AddField(
model_name='placeemailtemplate',
name='bcc_email_4',
field=models.EmailField(default=None, max_length=75, null=True, blank=True),
preserve_default=True,
),
migrations.AddField(
model_name='placeemailtemplate',
name='bcc_email_5',
field=models.EmailField(default=None, max_length=75, null=True, blank=True),
preserve_default=True,
),
]
6 changes: 5 additions & 1 deletion src/sa_api_v2/models/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,11 @@ class PlaceEmailTemplate (TimeStampedModel):
event = models.CharField(max_length=128, choices=EVENT_CHOICES, default='add')
recipient_email_field = models.CharField(max_length=128)
from_email = models.EmailField()
bcc_email = models.EmailField(blank=True, default=None)
bcc_email_1 = models.EmailField(blank=True, null=True, default=None)
bcc_email_2 = models.EmailField(blank=True, null=True, default=None)
bcc_email_3 = models.EmailField(blank=True, null=True, default=None)
bcc_email_4 = models.EmailField(blank=True, null=True, default=None)
bcc_email_5 = models.EmailField(blank=True, null=True, default=None)
subject = models.CharField(max_length=512)
body_text = models.TextField()
body_html = models.TextField(blank=True, default=None)
Expand Down
27 changes: 13 additions & 14 deletions src/sa_api_v2/views/base_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1231,6 +1231,12 @@ def trigger_emails(self, email_templates, obj):
logger.info('[EMAIL] Starting email send')

from_email = email_template.from_email
bcc_sources = [email_template.bcc_email_1,
email_template.bcc_email_2,
email_template.bcc_email_3,
email_template.bcc_email_4,
email_template.bcc_email_5]
bcc_list = [source for source in bcc_sources if source]

logger.debug('[EMAIL] Got from email')

Expand All @@ -1241,12 +1247,16 @@ def trigger_emails(self, email_templates, obj):
recipient_email = self.request.DATA[email_field]
logger.debug('[EMAIL] recipient_email: ' + recipient_email)
except KeyError:
errors.append("No '%s' field found on the place. "
"Be sure to configure the 'notifications.submitter_"
"email_field' property if necessary." % (email_field,))
logger.debug('[EMAIL] No primary recipient found. Setting primary recipient to the empty string.')
recipient_email = ""

logger.debug('[EMAIL] Got to email')

# If the user didn't provide an email address, and no BCC emails are provided,
# then we can't send an email
if not recipient_email and not bcc_list:
errors.append('[EMAIL] Error: No primary recipient and no BCC recipients provided. Email will not be sent.')

# Bail if any errors were found. Send all errors to the logs and otherwise
# fail silently.
if errors:
Expand All @@ -1256,17 +1266,6 @@ def trigger_emails(self, email_templates, obj):

logger.debug('[EMAIL] Going ahead, no errors')

# If the user didn't provide an email address, then no need to go further.
if not recipient_email:
return

logger.debug('[EMAIL] Going ahead, recipient exists')

# Set optional values
bcc_list = [email_template.bcc_email]

logger.debug('[EMAIL] Got bcc email')

# If we didn't find any errors, then render the email and send.
context_data = RequestContext(self.request, {
'place': obj,
Expand Down