Send an email to people interested in a course
This commit is contained in:
parent
2dd2d8dc41
commit
67adbd277c
19
apiserver/apiserver/api/emails/interest.html
Normal file
19
apiserver/apiserver/api/emails/interest.html
Normal 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>
|
11
apiserver/apiserver/api/emails/interest.txt
Normal file
11
apiserver/apiserver/api/emails/interest.txt
Normal 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
|
|
@ -67,3 +67,29 @@ def send_ical_email(member, session, ical_file):
|
||||||
msg.send()
|
msg.send()
|
||||||
|
|
||||||
logger.info('Sent ical email:\n' + email_text)
|
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)
|
||||||
|
|
|
@ -285,7 +285,19 @@ class SessionViewSet(Base, List, Retrieve, Create, Update):
|
||||||
return serializers.SessionSerializer
|
return serializers.SessionSerializer
|
||||||
|
|
||||||
def perform_create(self, serializer):
|
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):
|
def generate_ical(self, session):
|
||||||
cal = icalendar.Calendar()
|
cal = icalendar.Calendar()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user