Because we send messages out as a scheduled task with no request attribute, we need a way to configure the base url so we can host images in emails.
This commit is contained in:
parent
039da1b470
commit
2a5979d0e3
|
@ -34,7 +34,7 @@ class NotificationService(object):
|
||||||
def __init__(self, app):
|
def __init__(self, app):
|
||||||
self.app = app
|
self.app = app
|
||||||
self.sender = app.config['MAIL_SENDER']
|
self.sender = app.config['MAIL_SENDER']
|
||||||
self.BASE_HREF = app.config['APPLICATION_ROOT'].strip('/')
|
self.URL_ROOT = app.config['URL_ROOT']
|
||||||
|
|
||||||
def __enter__(self):
|
def __enter__(self):
|
||||||
if 'TESTING' in self.app.config and self.app.config['TESTING']:
|
if 'TESTING' in self.app.config and self.app.config['TESTING']:
|
||||||
|
@ -71,13 +71,13 @@ class NotificationService(object):
|
||||||
tracking_code = self._tracking_code()
|
tracking_code = self._tracking_code()
|
||||||
text_body = render_template("result_email.txt",
|
text_body = render_template("result_email.txt",
|
||||||
link=link,
|
link=link,
|
||||||
base_url = self.BASE_HREF,
|
base_url=self.URL_ROOT,
|
||||||
sample=sample,
|
sample=sample,
|
||||||
tracking_code=tracking_code)
|
tracking_code=tracking_code)
|
||||||
|
|
||||||
html_body = render_template("result_email.html",
|
html_body = render_template("result_email.html",
|
||||||
link=link,
|
link=link,
|
||||||
base_url = self.BASE_HREF,
|
base_url=self.URL_ROOT,
|
||||||
sample=sample,
|
sample=sample,
|
||||||
tracking_code=tracking_code)
|
tracking_code=tracking_code)
|
||||||
|
|
||||||
|
@ -92,13 +92,13 @@ class NotificationService(object):
|
||||||
text_body = render_template("invitation_email.txt",
|
text_body = render_template("invitation_email.txt",
|
||||||
date=date,
|
date=date,
|
||||||
location=location,
|
location=location,
|
||||||
base_url = self.BASE_HREF,
|
base_url=self.URL_ROOT,
|
||||||
tracking_code=tracking_code)
|
tracking_code=tracking_code)
|
||||||
|
|
||||||
html_body = render_template("invitation_email.html",
|
html_body = render_template("invitation_email.html",
|
||||||
date=date,
|
date=date,
|
||||||
location=location,
|
location=location,
|
||||||
base_url = self.BASE_HREF,
|
base_url=self.URL_ROOT,
|
||||||
tracking_code=tracking_code)
|
tracking_code=tracking_code)
|
||||||
|
|
||||||
self._send_email(subject, recipients=[self.sender], bcc=emails, text_body=text_body, html_body=html_body)
|
self._send_email(subject, recipients=[self.sender], bcc=emails, text_body=text_body, html_body=html_body)
|
||||||
|
|
|
@ -16,8 +16,12 @@ PRODUCTION = (environ.get('PRODUCTION', default="false") == "true")
|
||||||
ENABLE_SENTRY = environ.get('ENABLE_SENTRY', default="false") == "true" # To be removed soon
|
ENABLE_SENTRY = environ.get('ENABLE_SENTRY', default="false") == "true" # To be removed soon
|
||||||
SENTRY_ENVIRONMENT = environ.get('SENTRY_ENVIRONMENT', None)
|
SENTRY_ENVIRONMENT = environ.get('SENTRY_ENVIRONMENT', None)
|
||||||
|
|
||||||
# Add trailing slash to base path
|
# Add trailing slash to base path, typically this would be something like "/api/" don't use the full path!
|
||||||
APPLICATION_ROOT = re.sub(r'//', '/', '/%s/' % environ.get('APPLICATION_ROOT', default="/").strip('/'))
|
APPLICATION_ROOT = re.sub(r'//', '/', '/%s/' % environ.get('APPLICATION_ROOT', default="/").strip('/'))
|
||||||
|
# The full path to get to this, this is what would be returned form flask's request.url_root, but we won't
|
||||||
|
# have access to that in scheduled tasks run outside a request, this should include and match the APPLICATION_ROOT
|
||||||
|
# with no trailing backslask
|
||||||
|
URL_ROOT = environ.get('URL_ROOT', default="http://localhost:5000")
|
||||||
|
|
||||||
DB_HOST = environ.get('DB_HOST', default="localhost")
|
DB_HOST = environ.get('DB_HOST', default="localhost")
|
||||||
DB_PORT = environ.get('DB_PORT', default="5433")
|
DB_PORT = environ.get('DB_PORT', default="5433")
|
||||||
|
|
Loading…
Reference in New Issue