Private
Public Access
1
0

a few more templates

This commit is contained in:
Sander Roosendaal
2018-03-19 21:08:45 +01:00
parent ffed5c694b
commit ea30428f6e
11 changed files with 321 additions and 326 deletions

View File

@@ -32,35 +32,6 @@ from django_rq import job
from django.utils import timezone
from django.utils.html import strip_tags
def textify(html):
# Remove html tags and continuous whitespaces
text_only = re.sub('[ \t]+', ' ', strip_tags(html))
# Strip single spaces in the beginning of each line
return text_only.replace('\n ', '\n').strip()
def send_template_email(from_email,to_email,subject,template,context,*args,**kwargs):
htmly = get_template(template)
html_content = htmly.render(context)
text_content = textify(html_content)
msg = EmailMultiAlternatives(subject, text_content, from_email, to_email)
msg.attach_alternative(html_content, "text/html")
if 'emailbounced' in kwargs:
emailbounced = kwargs['emailbounced']
else:
emailbounced = False
if not emailbounced:
res = msg.send()
else:
return 0
return res
from utils import deserialize_list
from rowers.dataprepnodjango import (
@@ -90,6 +61,51 @@ import arrow
from django.contrib.staticfiles import finders
def textify(html):
# Remove html tags and continuous whitespaces
text_only = re.sub('[ \t]+', ' ', strip_tags(html))
# Strip single spaces in the beginning of each line
return text_only.replace('\n ', '\n').strip()
def send_template_email(from_email,to_email,subject,
template,context,
*args,**kwargs):
htmly = get_template(template)
html_content = htmly.render(context)
text_content = textify(html_content)
msg = EmailMultiAlternatives(subject, text_content, from_email, to_email)
msg.attach_alternative(html_content, "text/html")
if 'attach_file' in kwargs:
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)
msg.attach_file(fileobj2)
os.remove(fileobj2)
except IOError:
pass
if 'emailbounced' in kwargs:
emailbounced = kwargs['emailbounced']
else:
emailbounced = False
if not emailbounced:
res = msg.send()
else:
return 0
return res
@app.task
def add(x, y):
return x + y
@@ -357,8 +373,6 @@ def handle_sendemail_breakthrough(workoutid, useremail,
subject = "A breakthrough workout on rowsandall.com"
from_email = 'Rowsandall <info@rowsandall.com>'
htmly = get_template('breakthroughemail.html')
d = {
'first_name':userfirstname,
'siteurl':siteurl,
@@ -366,23 +380,13 @@ def handle_sendemail_breakthrough(workoutid, useremail,
'btvalues':tablevalues,
}
html_content = htmly.render(d)
text_content = textify(html_content)
msg = EmailMultiAlternatives(subject, text_content, from_email, [useremail])
msg.attach_alternative(html_content, "text/html")
if 'emailbounced' in kwargs:
emailbounced = kwargs['emailbounced']
else:
emailbounced = False
if not emailbounced:
res = msg.send()
res = send_template_email(from_email,[useremail],
subject,'breakthroughemail.html',
d,**kwargs)
# remove tcx file
return 1
# send email when a breakthrough workout is uploaded
@@ -403,12 +407,20 @@ def handle_sendemail_hard(workoutid, useremail,
if debug:
siteurl = SITE_URL_DEV
btvalues = pd.read_json(btvalues)
btvalues.sort_values('delta', axis=0, inplace=True)
tablevalues = [
{'delta': t.delta,
'cpvalue': t.cpvalues,
'pwr': t.pwr
} for t in btvalues.itertuples()
]
# send email with attachment
subject = "That was a pretty hard workout on rowsandall.com"
from_email = 'Rowsandall <info@rowsandall.com>'
htmly = get_template('hardemail.html')
d = {
'first_name':userfirstname,
'siteurl':siteurl,
@@ -416,24 +428,10 @@ def handle_sendemail_hard(workoutid, useremail,
'btvalues':tablevalues,
}
html_content = htmly.render(d)
text_content = textify(html_content)
msg = EmailMultiAlternatives(subject, text_content, from_email, [useremail])
msg.attach_alternative(html_content, "text/html")
res = send_template_email(from_email,[useremail],
subject,'hardemail.html',d,**kwargs)
if 'emailbounced' in kwargs:
emailbounced = kwargs['emailbounced']
else:
emailbounced = False
if not emailbounced:
res = msg.send()
# remove tcx file
return 1
@@ -511,27 +509,15 @@ def handle_sendemail_unrecognizedowner(useremail, userfirstname,
fullemail = useremail
subject = "Unrecognized file from Rowsandall.com"
plaintext = get_template('csvemail.txt')
htmly = get_template('csvemail.html')
htmly = get_template('unrecognizedemail.html')
d = {'first_name':first_name}
d = {'first_name':userfirstname}
from_email = 'Rowsandall <info@rowsandall.com>'
html_content = htmly.render(d)
text_content = textify(html_content)
msg = EmailMultiAlternatives(subject, text_content, from_email, [fullemail])
msg.attach_alternative(html_content, "text/html")
if 'emailbounced' in kwargs:
emailbounced = kwargs['emailbounced']
else:
emailbounced = False
if not emailbounced:
res = msg.send()
res = send_template_email(from_email,[fullemail],
subject,'csvemail.html',d,
**kwargs)
return 1
@@ -550,24 +536,11 @@ def handle_sendemailtcx(first_name, last_name, email, tcxfile,**kwargs):
from_email = 'Rowsandall <info@rowsandall.com>'
html_content = htmly.render(d)
text_content = textify(html_content)
msg = EmailMultiAlternatives(subject, text_content, from_email, [fullemail])
msg.attach_alternative(html_content, "text/html")
res = send_template_email(from_email,[fullemail],
subject,'tcxemail.html',d,
attach_file=tcxfile,**kwargs)
msg.attach_file(tcxfile)
if 'emailbounced' in kwargs:
emailbounced = kwargs['emailbounced']
else:
emailbounced = False
if not emailbounced:
res = msg.send()
# remove tcx file
os.remove(tcxfile)
return 1
@@ -612,31 +585,11 @@ def handle_sendemailsummary(first_name, last_name, email, csvfile, **kwargs):
from_email = 'Rowsandall <info@rowsandall.com>'
html_content = htmly.render(d)
text_content = textify(html_content)
msg = EmailMultiAlternatives(subject, text_content, from_email, [fullemail])
msg.attach_alternative(html_content, "text/html")
if os.path.isfile(csvfile):
msg.attach_file(csvfile)
else:
csvfile2 = csvfile
with gzip.open(csvfile + '.gz', 'rb') as f_in, open(csvfile2, 'wb') as f_out:
shutil.copyfileobj(f_in, f_out)
msg.attach_file(csvfile2)
os.remove(csvfile2)
if 'emailbounced' in kwargs:
emailbounced = kwargs['emailbounced']
else:
emailbounced = False
if not emailbounced:
res = msg.send()
res = send_template_email(from_email,[fullemail],
subject,'summarymail.html',d,
attach_file=csvfile,
**kwargs)
try:
os.remove(csvfile)
except:
@@ -654,37 +607,15 @@ def handle_sendemailcsv(first_name, last_name, email, csvfile,**kwargs):
fullemail = first_name + " " + last_name + " " + "<" + email + ">"
subject = "File from Rowsandall.com"
htmly = get_template('csvemail.html')
d = {'first_name':first_name}
from_email = 'Rowsandall <info@rowsandall.com>'
html_content = htmly.render(d)
text_content = textify(html_content)
msg = EmailMultiAlternatives(subject, text_content, from_email, [fullemail])
msg.attach_alternative(html_content, "text/html")
if os.path.isfile(csvfile):
msg.attach_file(csvfile)
else:
csvfile2 = csvfile
with gzip.open(csvfile + '.gz', 'rb') as f_in, open(csvfile2, 'wb') as f_out:
shutil.copyfileobj(f_in, f_out)
msg.attach_file(csvfile2)
os.remove(csvfile2)
if 'emailbounced' in kwargs:
emailbounced = kwargs['emailbounced']
else:
emailbounced = False
if not emailbounced:
res = msg.send()
res = send_template_email(from_email,[fullemail],
subject,'csvemail.html',d,
attach_file=csvfile,**kwargs)
return 1
@@ -819,22 +750,9 @@ def handle_otwsetpower(self,f1, boattype, weightvalue,
'workoutid':workoutid,
}
html_content = htmly.render(d)
text_content = textify(html_content)
msg = EmailMultiAlternatives(subject, text_content, from_email, [fullemail])
msg.attach_alternative(html_content, "text/html")
if 'emailbounced' in kwargs:
emailbounced = kwargs['emailbounced']
else:
emailbounced = False
if not emailbounced:
res = msg.send()
res = handle_template_email(from_email,[fullemail],
subject,'otwpoweremail.html',d,
**kwargs)
return 1
@@ -1062,30 +980,20 @@ def handle_sendemail_invite(email, name, code, teamname, manager,
if debug:
siteurl = SITE_URL_DEV
htmly = get_template('teaminviteemail.html')
d = {
'name':name,
'manage':manager,
'manager':manager,
'code':code,
'teamname':teamname,
'siteurl':siteurl
}
html_content = htmly.render(d)
text_content = textify(html_content)
from_email = 'Rowsandall <info@rowsandall.com>'
res = send_template_email(from_email,[fullemail],
subject,'teaminviteemail.html',d,
**kwargs)
msg = EmailMultiAlternatives(subject, text_content, from_email, [fullemail])
msg.attach_alternative(html_content, "text/html")
if 'emailbounced' in kwargs:
emailbounced = kwargs['emailbounced']
else:
emailbounced = False
if not emailbounced:
res = msg.send()
return 1
@@ -1106,8 +1014,6 @@ def handle_sendemailnewresponse(first_name, last_name,
siteurl = SITE_URL_DEV
htmly = get_template('teamresponseemail.html')
d = {
'first_name':first_name,
'commenter_first_name':commenter_first_name,
@@ -1133,30 +1039,32 @@ def handle_sendemailnewcomment(first_name,
comment, workoutname,
workoutid,
debug=False,**kwargs):
fullemail = first_name + ' ' + last_name + ' <' + email + '>'
from_email = 'Rowsandall <info@rowsandall.com>'
subject = 'New comment on workout ' + workoutname
message = 'Dear ' + first_name + ',\n\n'
message += commenter_first_name + ' ' + commenter_last_name
message += ' has written a new comment on your workout '
message += workoutname + '\n\n'
message += comment
message += '\n\n'
message += 'You can read the comment here:\n'
message += 'https://rowsandall.com/rowers/workout/' + \
str(workoutid) + '/comment'
email = EmailMessage(subject, message,
'Rowsandall <info@rowsandall.com>',
[fullemail])
siteurl = SITE_URL
if debug:
siteurl = SITE_URL_DEV
if 'emailbounced' in kwargs:
emailbounced = kwargs['emailbounced']
else:
emailbounced = False
d = {
'first_name':first_name,
'commenter_first_name':commenter_first_name,
'commenter_last_name':commenter_last_name,
'comment':comment,
'workoutname':workoutname,
'siteurl':siteurl,
'workoutid':workoutid,
'commentid':commentid
}
if not emailbounced:
res = email.send()
res = send_template_email(from_email,[fullemail],subject,
'teamresponseemail.html',d,**kwargs)
return 1
@@ -1166,29 +1074,23 @@ def handle_sendemail_request(email, name, code, teamname, requestor, id,
debug=False,**kwargs):
fullemail = name + ' <' + email + '>'
subject = 'Request to join team ' + teamname
message = 'Dear ' + name + ',\n\n'
message += requestor + ' is requesting admission to your team ' + teamname
message += ' on rowsandall.com\n\n'
message += 'Click the direct link to accept: \n'
message += 'https://rowsandall.com/rowers/me/request/' + code + ' \n\n'
message += 'Click the following link to reject the request: \n'
message += 'https://rowsandall.com/rowers/me/request/' + str(id) + ' \n\n'
message += 'You can find all pending requests on your team management page:\n'
message += 'https://rowsandall.com/rowers/me/teams\n\n'
message += "Best Regards, the Rowsandall Team"
from_email = 'Rowsandall <info@rowsandall.com>'
email = EmailMessage(subject, message,
'Rowsandall <info@rowsandall.com>',
[fullemail])
siteurl = SITE_URL
if debug:
siteurl = SITE_URL_DEV
if 'emailbounced' in kwargs:
emailbounced = kwargs['emailbounced']
else:
emailbounced = False
d = {
'requestor':requestor,
'teamname':teamname,
'siteurl':siteurl,
'id':id,
'first_name':name,
}
res = send_template_email(from_email,[fullemail],subject,
'teamrequestemail.html',d,**kwargs)
if not emailbounced:
res = email.send()
return 1
@@ -1198,25 +1100,20 @@ def handle_sendemail_request_accept(email, name, teamname, managername,
debug=False,**kwargs):
fullemail = name + ' <' + email + '>'
subject = 'Welcome to ' + teamname
message = 'Dear ' + name + ',\n\n'
message += managername
message += ' has accepted your request to be part of the team '
message += teamname
message += '\n\n'
message += "Best Regards, the Rowsandall Team"
from_email = 'Rowsandall <info@rowsandall.com>'
email = EmailMessage(subject, message,
'Rowsandall <info@rowsandall.com>',
[fullemail])
siteurl = SITE_URL
if debug:
siteurl = SITE_URL_DEV
if 'emailbounced' in kwargs:
emailbounced = kwargs['emailbounced']
else:
emailbounced = False
d = {
'first_name':name,
'managername':managername,
'teamname':teamname,
}
res = send_template_email(from_email,[fullemail],subject,
'teamwelcomeemail.html',d,**kwargs)
if not emailbounced:
res = email.send()
return 1
@@ -1226,26 +1123,19 @@ def handle_sendemail_request_reject(email, name, teamname, managername,
debug=False,**kwargs):
fullemail = name + ' <' + email + '>'
subject = 'Your application to ' + teamname + ' was rejected'
message = 'Dear ' + name + ',\n\n'
message += 'Unfortunately, '
message += managername
message += ' has rejected your request to be part of the team '
message += teamname
message += '\n\n'
message += "Best Regards, the Rowsandall Team"
from_email = 'Rowsandall <info@rowsandall.com>'
email = EmailMessage(subject, message,
'Rowsandall <info@rowsandall.com>',
[fullemail])
siteurl = SITE_URL
if debug:
siteurl = SITE_URL_DEV
if 'emailbounced' in kwargs:
emailbounced = kwargs['emailbounced']
else:
emailbounced = False
if not emailbounced:
res = email.send()
d = {
'first_name':name,
'managername':managername,
'teamname':teamname,
}
res = send_template_email(from_email,[fullemail],subject,
'teamrejectemail.html',d,**kwargs)
return 1
@@ -1255,26 +1145,20 @@ def handle_sendemail_member_dropped(email, name, teamname, managername,
debug=False,**kwargs):
fullemail = name + ' <' + email + '>'
subject = 'You were removed from ' + teamname
message = 'Dear ' + name + ',\n\n'
message += 'Unfortunately, '
message += managername
message += ' has removed you from the team '
message += teamname
message += '\n\n'
message += "Best Regards, the Rowsandall Team"
from_email = 'Rowsandall <info@rowsandall.com>'
email = EmailMessage(subject, message,
'Rowsandall <info@rowsandall.com>',
[fullemail])
siteurl = SITE_URL
if debug:
siteurl = SITE_URL_DEV
if 'emailbounced' in kwargs:
emailbounced = kwargs['emailbounced']
else:
emailbounced = False
d = {
'first_name':name,
'managername':managername,
'teamname':teamname,
}
res = send_template_email(from_email,[fullemail],subject,
'teamdropemail.html',d,**kwargs)
if not emailbounced:
res = email.send()
return 1
@@ -1282,29 +1166,23 @@ def handle_sendemail_member_dropped(email, name, teamname, managername,
@app.task
def handle_sendemail_team_removed(email, name, teamname, managername,
debug=False,**kwargs):
fullemail = name + ' <' + email + '>'
subject = 'Team ' + teamname + ' was deleted'
message = 'Dear ' + name + ',\n\n'
message += managername
message += ' has decided to delete the team '
message += teamname
message += '\n\n'
message += 'The ' + teamname + ' tag has been removed from all your '
message += 'workouts on rowsandall.com.\n\n'
message += "Best Regards, the Rowsandall Team"
subject = 'You were removed from ' + teamname
from_email = 'Rowsandall <info@rowsandall.com>'
email = EmailMessage(subject, message,
'Rowsandall <info@rowsandall.com>',
[fullemail])
siteurl = SITE_URL
if debug:
siteurl = SITE_URL_DEV
if 'emailbounced' in kwargs:
emailbounced = kwargs['emailbounced']
else:
emailbounced = False
d = {
'first_name':name,
'managername':managername,
'teamname':teamname,
}
res = send_template_email(from_email,[fullemail],subject,
'teamremoveemail.html',d,**kwargs)
if not emailbounced:
res = email.send()
return 1
@@ -1314,26 +1192,20 @@ def handle_sendemail_invite_reject(email, name, teamname, managername,
debug=False,**kwargs):
fullemail = managername + ' <' + email + '>'
subject = 'Your invitation to ' + name + ' was rejected'
message = 'Dear ' + managername + ',\n\n'
message += 'Unfortunately, '
message += name
message += ' has rejected your invitation to be part of the team '
message += teamname
message += '\n\n'
message += "Best Regards, the Rowsandall Team"
email = EmailMessage(subject, message,
'Rowsandall <info@rowsandall.com>',
[fullemail])
from_email = 'Rowsandall <info@rowsandall.com>'
if 'emailbounced' in kwargs:
emailbounced = kwargs['emailbounced']
else:
emailbounced = False
siteurl = SITE_URL
if debug:
siteurl = SITE_URL_DEV
if not emailbounced:
res = email.send()
d = {
'first_name':name,
'managername':managername,
'teamname':teamname,
}
res = send_template_email(from_email,[fullemail],subject,
'teaminviterejectemail.html',d,**kwargs)
return 1
@@ -1343,22 +1215,21 @@ def handle_sendemail_invite_accept(email, name, teamname, managername,
debug=False,**kwargs):
fullemail = managername + ' <' + email + '>'
subject = 'Your invitation to ' + name + ' was accepted'
message = 'Dear ' + managername + ',\n\n'
message += name + ' has accepted your invitation to be part of the team ' + teamname + '\n\n'
message += "Best Regards, the Rowsandall Team"
email = EmailMessage(subject, message,
'Rowsandall <info@rowsandall.com>',
[fullemail])
from_email = 'Rowsandall <info@rowsandall.com>'
if 'emailbounced' in kwargs:
emailbounced = kwargs['emailbounced']
else:
emailbounced = False
siteurl = SITE_URL
if debug:
siteurl = SITE_URL_DEV
d = {
'first_name':name,
'managername':managername,
'teamname':teamname,
}
res = send_template_email(from_email,[fullemail],subject,
'teaminviteacceptemail.html',d,**kwargs)
if not emailbounced:
res = email.send()
return 1

View File

@@ -393,6 +393,7 @@ def send_request_email(rekwest):
code = rekwest.code
teamname = rekwest.team.name
requestor = rekwest.user.first_name+' '+rekwest.user.last_name
print requestor,'aap'
res = myqueue(queuehigh,
handle_sendemail_request,

View File

@@ -0,0 +1,16 @@
{% extends "emailbase.html" %}
{% load staticfiles %}
{% load rowerfilters %}
{% block body %}
<p>Dear <strong>{{ first_name }}</strong>,</p>
<p>
Unfortunately,
{{ managername }} has removed you from
the team {{ teamname }}.
</p>
<p>
Best Regards, the Rowsandall Team
</p>
{% endblock %}

View File

@@ -0,0 +1,16 @@
{% extends "emailbase.html" %}
{% load staticfiles %}
{% load rowerfilters %}
{% block body %}
<p>Dear <strong>{{ managername }}</strong>,</p>
<p>
{{ first_name }} has accepted your invitation to be
part of the team {{ teamname }}.
</p>
<p>
Best Regards, the Rowsandall Team
</p>
{% endblock %}

View File

@@ -0,0 +1,17 @@
{% extends "emailbase.html" %}
{% load staticfiles %}
{% load rowerfilters %}
{% block body %}
<p>Dear <strong>{{ managername }}</strong>,</p>
<p>
Unfortunately,
{{ first_name }} has rejected your invitation to be
part of the team {{ teamname }}.
</p>
<p>
Best Regards, the Rowsandall Team
</p>
{% endblock %}

View File

@@ -0,0 +1,16 @@
{% extends "emailbase.html" %}
{% load staticfiles %}
{% load rowerfilters %}
{% block body %}
<p>Dear <strong>{{ first_name }}</strong>,</p>
<p>
Unfortunately,
{{ managername }} has rejected your request to be part
of the team {{ teamname }}.
</p>
<p>
Best Regards, the Rowsandall Team
</p>
{% endblock %}

View File

@@ -0,0 +1,19 @@
{% extends "emailbase.html" %}
{% load staticfiles %}
{% load rowerfilters %}
{% block body %}
<p>Dear <strong>{{ first_name }}</strong>,</p>
<p>
{{ managername }} has decided to delete the team {{ teamname }}.
</p>
<p>
The {{ teamname }} tag has been removed from all your
workouts on rowsandall.com
</p>
<p>
Best Regards, the Rowsandall Team
</p>
{% endblock %}

View File

@@ -0,0 +1,29 @@
{% extends "emailbase.html" %}
{% load staticfiles %}
{% load rowerfilters %}
{% block body %}
<p>Dear <strong>{{ first_name }}</strong>,</p>
<p>
{{ requestor }} is requesting access to your team {{ teamname }}
on rowsandall.com
</p>
<p>
Click the direct link to accept:
<a href="{{ siteurl }}/rowers/me/request/{{ code }}">
{{ siteurl }}/rowers/me/request/{{ code }}</a>
</p>
<p>
Click the following link to reject the request:
<a href="{{ siteurl }}/rowers/me/request/{{ id }}">
{{ siteurl }}/rowers/me/request/{{ id }}</a>
</p>
<p>
You can find all pending requests on your team management page:
<a href="{{ siteurl }}/rowers/me/teams">{{ siteurl }}/rowers/me/teams</a>
</p>
<p>
Best Regards, the Rowsandall Team
</p>
{% endblock %}

View File

@@ -7,7 +7,7 @@
<p>
{{ commenter_first_name }} {{ commenter_last_name }} has written
a new comment on your workout {{ workoutname }}
a new comment on workout {{ workoutname }}
</p>
<p>
{{ comment }}

View File

@@ -0,0 +1,15 @@
{% extends "emailbase.html" %}
{% load staticfiles %}
{% load rowerfilters %}
{% block body %}
<p>Dear <strong>{{ first_name }}</strong>,</p>
<p>
{{ managername }} has accepted your request to be part
of the team {{ teamname }}.
</p>
<p>
Best Regards, the Rowsandall Team
</p>
{% endblock %}

View File

@@ -1,5 +0,0 @@
---
aap: noot
mies: jet
jet
...