Add progress to class creation, fix interest emails

If there's 20 people interested in a course, class creation could take
quite a while so show progress. Only send emails to active members.
Change "Interest +" wording to "interested" in emails.
This commit is contained in:
2022-09-05 22:01:46 +00:00
parent 2d76aaf87d
commit 4f121d0541
6 changed files with 46 additions and 9 deletions

View File

@@ -12,7 +12,7 @@
<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>Your "interest" in this course is now removed and you won't receive any more notifications about its classes until you press the "interested" button again.<br></div>
<div><br></div>
<div>Spaceport<br></div>
</body>

View File

@@ -6,6 +6,6 @@ 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.
notifications about its classes until you press the "interested" button again.
Spaceport

View File

@@ -3,6 +3,7 @@ logger = logging.getLogger(__name__)
import os
import smtplib
import time
from datetime import datetime, timedelta
from django.core.mail import send_mail, EmailMultiAlternatives
@@ -92,4 +93,7 @@ def send_interest_email(interest):
html_message=email_html,
)
if not settings.EMAIL_HOST:
time.sleep(0.5) # simulate slowly sending emails when logging to console
logger.info('Sent interest email:\n' + email_text)

View File

@@ -195,8 +195,13 @@ def calc_card_scans():
def get_progress(request_id):
return cache.get('request-progress-' + request_id, [])
def set_progress(request_id, data):
def set_progress(request_id, data, replace=False):
logger.info('Progress - ID: %s | Status: %s', request_id, data)
progress = get_progress(request_id)
progress.append(data)
if replace and len(progress):
progress[-1] = data
else:
progress.append(data)
cache.set('request-progress-' + request_id, progress)

View File

@@ -279,6 +279,7 @@ class SessionViewSet(Base, List, Retrieve, Create, Update):
return serializers.SessionSerializer
def perform_create(self, serializer):
data = self.request.data
session = serializer.save(instructor=self.request.user)
# ensure session datetime is at least 1 day in the future
@@ -287,15 +288,22 @@ class SessionViewSet(Base, List, Retrieve, Create, Update):
logging.info('Session is in the past or too soon, not sending interest emails.')
return
interests = models.Interest.objects.filter(course=session.course, satisfied_by__isnull=True)
interests = models.Interest.objects.filter(
course=session.course,
satisfied_by__isnull=True,
user__member__paused_date__isnull=True
)
for num, interest in enumerate(interests):
msg = 'Sending email {} / {}...'.format(num+1, len(interests))
if data['request_id']: utils_stats.set_progress(data['request_id'], msg, replace=True)
for interest in interests:
try:
utils_email.send_interest_email(interest)
except BaseException as e:
msg = 'Problem sending interest email: ' + str(e)
logger.exception(msg)
alert_tanner(msg)
utils.alert_tanner(msg)
num_satisfied = interests.update(satisfied_by=session)
logging.info('Satisfied %s interests.', num_satisfied)