commit
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
from __future__ import absolute_import
|
||||
from django.contrib.staticfiles import finders
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
from __future__ import unicode_literals
|
||||
@@ -40,16 +41,13 @@ from django.utils.html import strip_tags
|
||||
|
||||
from django.core.mail import (
|
||||
send_mail,
|
||||
EmailMessage,EmailMultiAlternatives,
|
||||
)
|
||||
EmailMessage, EmailMultiAlternatives,
|
||||
)
|
||||
|
||||
from django.template import Context
|
||||
from django.db.utils import OperationalError
|
||||
from jinja2 import Template,Environment,FileSystemLoader
|
||||
env = Environment(loader = FileSystemLoader(["rowers/templates"]))
|
||||
|
||||
from django.contrib.staticfiles import finders
|
||||
|
||||
from jinja2 import Template, Environment, FileSystemLoader
|
||||
env = Environment(loader=FileSystemLoader(["rowers/templates"]))
|
||||
|
||||
|
||||
def textify(html):
|
||||
@@ -58,21 +56,25 @@ def textify(html):
|
||||
# Strip single spaces in the beginning of each line
|
||||
return text_only.replace('\n ', '\n').strip()
|
||||
|
||||
|
||||
def htmlstripnobr(html):
|
||||
safe_html = re.sub('[ \t]+', ' ', strip_tags(html))
|
||||
return safe_html
|
||||
|
||||
|
||||
def htmlstrip(html):
|
||||
safe_html = re.sub('[ \t]+', ' ', strip_tags(html))
|
||||
return newlinetobr(safe_html)
|
||||
|
||||
def newlinetobr(html):
|
||||
html = html.replace('\n\n','<br>')
|
||||
return html.replace('\n','<br>')
|
||||
|
||||
def send_template_email(from_email,to_email,subject,
|
||||
template,context,
|
||||
*args,**kwargs):
|
||||
def newlinetobr(html):
|
||||
html = html.replace('\n\n', '<br>')
|
||||
return html.replace('\n', '<br>')
|
||||
|
||||
|
||||
def send_template_email(from_email, to_email, subject,
|
||||
template, context,
|
||||
*args, **kwargs):
|
||||
|
||||
htmly = env.get_template(template)
|
||||
|
||||
@@ -80,60 +82,61 @@ def send_template_email(from_email,to_email,subject,
|
||||
text_content = textify(html_content)
|
||||
# html_content = newlinetobr(html_content)
|
||||
|
||||
|
||||
if 'bcc' in kwargs and 'cc' in kwargs: # pragma: no cover
|
||||
msg = EmailMultiAlternatives(subject, text_content, from_email, to_email,cc=kwargs['cc'],
|
||||
if 'bcc' in kwargs and 'cc' in kwargs: # pragma: no cover
|
||||
msg = EmailMultiAlternatives(subject, text_content, from_email, to_email, cc=kwargs['cc'],
|
||||
bcc=kwargs['bcc'])
|
||||
elif 'bcc' in kwargs: # pragma: no cover
|
||||
msg = EmailMultiAlternatives(subject, text_content, from_email, to_email,bcc=kwargs['bcc'])
|
||||
elif 'cc' in kwargs: # pragma: no cover
|
||||
msg = EmailMultiAlternatives(subject, text_content, from_email, to_email,cc=kwargs['cc'])
|
||||
elif 'bcc' in kwargs: # pragma: no cover
|
||||
msg = EmailMultiAlternatives(
|
||||
subject, text_content, from_email, to_email, bcc=kwargs['bcc'])
|
||||
elif 'cc' in kwargs: # pragma: no cover
|
||||
msg = EmailMultiAlternatives(
|
||||
subject, text_content, from_email, to_email, cc=kwargs['cc'])
|
||||
else:
|
||||
msg = EmailMultiAlternatives(subject, text_content, from_email, to_email)
|
||||
msg = EmailMultiAlternatives(
|
||||
subject, text_content, from_email, to_email)
|
||||
|
||||
msg.attach_alternative(html_content, "text/html")
|
||||
|
||||
if 'attach_file' in kwargs: # pragma: no cover
|
||||
if 'attach_file' in kwargs: # pragma: no cover
|
||||
fileobj = kwargs['attach_file']
|
||||
if os.path.isfile(fileobj):
|
||||
msg.attach_file(fileobj)
|
||||
else:
|
||||
try:
|
||||
fileobj2 = fileobj
|
||||
with gzip.open(fileobj+'.gz','rb') as f_in, open(fileobj2,'wb') as f_out:
|
||||
shutil.copyfileobj(f_in,f_out)
|
||||
with gzip.open(fileobj+'.gz', 'rb') as f_in, open(fileobj2, 'wb') as f_out:
|
||||
shutil.copyfileobj(f_in, f_out)
|
||||
msg.attach_file(fileobj2)
|
||||
os.remove(fileobj2)
|
||||
except IOError:
|
||||
pass
|
||||
|
||||
if 'emailbounced' in kwargs: # pragma: no cover
|
||||
if 'emailbounced' in kwargs: # pragma: no cover
|
||||
emailbounced = kwargs['emailbounced']
|
||||
else:
|
||||
emailbounced = False
|
||||
|
||||
|
||||
|
||||
if not emailbounced:
|
||||
res = msg.send()
|
||||
else: # pragma: no cover
|
||||
else: # pragma: no cover
|
||||
return 0
|
||||
|
||||
return res
|
||||
|
||||
def send_confirm(user, name, link, options): # pragma: no cover
|
||||
|
||||
def send_confirm(user, name, link, options): # pragma: no cover
|
||||
d = {
|
||||
'first_name':user.first_name,
|
||||
'name':name,
|
||||
'link':link,
|
||||
}
|
||||
'first_name': user.first_name,
|
||||
'name': name,
|
||||
'link': link,
|
||||
}
|
||||
|
||||
fullemail = user.email
|
||||
subject = 'New Workout Added: '+name
|
||||
|
||||
res = send_template_email('Rowsandall <info@rowsandall.com>',
|
||||
[fullemail],
|
||||
subject,'confirmemail.html',
|
||||
subject, 'confirmemail.html',
|
||||
d
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user