diff --git a/items/models.py b/items/models.py
index dd549de..71a195b 100644
--- a/items/models.py
+++ b/items/models.py
@@ -1,6 +1,7 @@
from __future__ import unicode_literals
from django.contrib.auth.models import User
from django.core.mail import send_mail
+from django.template import loader
from storages.backends.s3boto3 import S3Boto3Storage
from stdimage.models import StdImageField
from datetime import datetime, date
@@ -61,46 +62,49 @@ class Item(models.Model):
return self.committee.name + ": " + self.event + " " + self.desc
def mail_com_chair(self):
+ template = loader.get_template('items/item-email.html')
+ context_plain = {
+ 'I': self,
+ 'to': self.committee.chair.first_name,
+ 'submitter': self.created_by.first_name + ' ' + self.created_by.last_name,
+ }
+ context_html = {
+ 'I': self,
+ 'to': self.committee.chair.first_name,
+ 'submitter': self.created_by.first_name + ' ' + self.created_by.last_name,
+ 'html': True,
+ }
+
send_mail(
'New Reimbursement - ' + self.event + ': ' + self.desc,
- 'Hey ' + self.committee.chair.first_name + ',\n\n' + \
- 'Please take a moment to review http://fincom.delt.space/items/' + \
- str(self.pk) + ' and approve or reject the request from ' + \
- self.created_by.first_name + ' ' + self.created_by.last_name + \
- '. If you have any questions, contact the treasurer.\n\n' + \
- 'Have a fiscally responsible day,\n Fincom Bot',
+ template.render(context_plain),
'fincom.bot@gmail.com',
[self.committee.chair.email],
- html_message='Hey ' + self.committee.chair.first_name+',
' +\
- 'Please take a moment to review ' + \
- 'http://fincom.delt.space/items/' + str(self.pk) +\
- ' and approve or reject the request from ' + \
- self.created_by.first_name + ' ' + self.created_by.last_name + \
- '. If you have any questions, contact the treasurer.
' + \
- 'Have a fiscally responsible day,
Fincom Bot'
+ html_message=template.render(context_html),
)
def mail_fincom(self):
emails = [s.email for s in User.objects.filter(groups__name='Fincom')]
+ template = loader.get_template('items/item-email.html')
+ context_plain = {
+ 'I': self,
+ 'to': 'Fincom',
+ 'submitter': self.created_by.first_name + ' ' + self.created_by.last_name,
+ }
+ context_html = {
+ 'I': self,
+ 'to': 'Fincom',
+ 'submitter': self.created_by.first_name + ' ' + self.created_by.last_name,
+ 'html': True,
+ }
+
send_mail(
'Preapproved Reimbursement - ' + self.event + ': ' + self.desc,
- 'Hey Fincom,\n\n' + \
- 'Please take a moment to review http://fincom.delt.space/items/' + \
- str(self.pk) + ' and approve or reject the request from ' + \
- self.created_by.first_name + ' ' + self.created_by.last_name + \
- '.\n\nHave a fiscally responsible day,\n Fincom Bot',
+ template.render(context_plain),
'fincom.bot@gmail.com',
emails,
- html_message='Hey Fincom,
' + \
- 'Please take a moment to review ' + \
- 'http://fincom.delt.space/items/' + str(self.pk) +\
- ' and approve or reject the request from ' + \
- self.created_by.first_name + ' ' + self.created_by.last_name + \
- '.
' + \
- 'Have a fiscally responsible day,
Fincom Bot'
+ html_message=template.render(context_html),
)
@staticmethod
diff --git a/templates/items/item-email.html b/templates/items/item-email.html
new file mode 100644
index 0000000..da1e0e3
--- /dev/null
+++ b/templates/items/item-email.html
@@ -0,0 +1,53 @@
+Hey {{ to }},
+
+Please review and then approve or reject the request from {{ submitter }} for {{ I.event }}: {{ I.desc }} by going to {% if html %}{% endif %}http://fincom.delt.space/items/{{ I.pk }}{% if html %}.
{% endif %}
+
+{% if html %}
+