Send an email to people interested in a course

This commit is contained in:
Tanner Collin 2022-05-04 23:02:39 +00:00
parent 2dd2d8dc41
commit 67adbd277c
4 changed files with 69 additions and 1 deletions

View File

@ -0,0 +1,19 @@
<!DOCTYPE html>
<html>
<head>
<title></title>
<style type="text/css">p.MsoNormal,p.MsoNoSpacing{margin:0}</style>
</head>
<body>
<div>Hi [name],<br></div>
<div><br></div>
<div>There's been a class scheduled for [course] that you expressed interest in.<br></div>
<div><br></div>
<div>You can find the class on its course page here:<br></div>
<div><a href="[link]">[link]</a><br></div>
<div><br></div>
<div>Your "interest" in this course is now removed and you won't receive any more notifications about its classes until you press the "Interest +" button again.<br></div>
<div><br></div>
<div>Spaceport<br></div>
</body>
</html>

View File

@ -0,0 +1,11 @@
Hi [name],
There's been a class scheduled for [course] that you expressed interest in.
You can find the class on its course page here:
[link]
Your "interest" in this course is now removed and you won't receive any more
notifications about its classes until you press the "Interest +" button again.
Spaceport

View File

@ -67,3 +67,29 @@ def send_ical_email(member, session, ical_file):
msg.send()
logger.info('Sent ical email:\n' + email_text)
def send_interest_email(interest):
def replace_fields(text):
return text.replace(
'[name]', interest.user.member.first_name,
).replace(
'[course]', interest.course.name,
).replace(
'[link]', 'https://my.protospace.ca/courses/' + str(interest.course.id),
)
with open(EMAIL_DIR + 'interest.txt', 'r') as f:
email_text = replace_fields(f.read())
with open(EMAIL_DIR + 'interest.html', 'r') as f:
email_html = replace_fields(f.read())
send_mail(
subject='Protospace class scheduled',
message=email_text,
from_email=None, # defaults to DEFAULT_FROM_EMAIL
recipient_list=[interest.user.email],
html_message=email_html,
)
logger.info('Sent interest email:\n' + email_text)

View File

@ -285,7 +285,19 @@ class SessionViewSet(Base, List, Retrieve, Create, Update):
return serializers.SessionSerializer
def perform_create(self, serializer):
serializer.save(instructor=self.request.user)
session = serializer.save(instructor=self.request.user)
interests = models.Interest.objects.filter(course=session.course, satisfied_by__isnull=True)
for interest in interests:
try:
utils_email.send_interest_email(interest)
except BaseException as e:
msg = 'Problem interest email: ' + str(e)
logger.exception(msg)
alert_tanner(msg)
num_satisfied = interests.update(satisfied_by=session)
logging.info('Satisfied %s interests.', num_satisfied)
def generate_ical(self, session):
cal = icalendar.Calendar()