# Launch all campaigns
self.db.execute("INSERT INTO campaign_emails(account_uid, template, \
- launch_at, repeat_after) \
+ launch_at, repeat_after, promotional) \
SELECT %s, template, COALESCE(launch_at, CURRENT_TIMESTAMP + launch_after), \
- repeat_after FROM campaign_templates WHERE name = %s",
+ repeat_after, promotional FROM campaign_templates WHERE name = %s",
account.uid, name)
def _get_campaign_emails(self, query, *args):
def repeat_after(self):
return self.data.repeat_after
+ @property
+ def promotional(self):
+ return self.data.promotional
+
+ @property
+ def should_be_sent(self):
+ # Send all non-promotional emails
+ if not self.promotional:
+ return True
+
+ # For promotional emails, send them if we have consent
+ return self.account.consents_to_promotional_emails
+
def send(self):
# Delete if the account does not exist any more
if not self.account:
logging.debug("Sending %s to %s" % (self.template, self.account))
# Generate the email
- self.backend.messages.send_template(self.template, account=self.account)
+ if self.should_be_sent:
+ self.backend.messages.send_template(self.template, account=self.account)
# Update this email for the next launch
self._update()