Test sending reminders for instructors to mark attendance
This commit is contained in:
parent
8995a8fc98
commit
7bd1c9f175
|
@ -35,6 +35,8 @@ class Command(BaseCommand):
|
||||||
utils.gen_search_strings()
|
utils.gen_search_strings()
|
||||||
|
|
||||||
def send_class_reminders(self):
|
def send_class_reminders(self):
|
||||||
|
# sends reminders to instructors that they are teaching a class
|
||||||
|
# within 6-7 hours from now
|
||||||
count = 0
|
count = 0
|
||||||
|
|
||||||
now = utils.now_alberta_tz()
|
now = utils.now_alberta_tz()
|
||||||
|
@ -91,6 +93,73 @@ class Command(BaseCommand):
|
||||||
|
|
||||||
return count
|
return count
|
||||||
|
|
||||||
|
def send_attendance_reminders(self):
|
||||||
|
# sends reminders to instructors to mark attendance for classes
|
||||||
|
# that happened 6-7 hours ago if they haven't already
|
||||||
|
count = 0
|
||||||
|
|
||||||
|
now = utils.now_alberta_tz()
|
||||||
|
current_hour_start = now.replace(minute=0, second=0, microsecond=0)
|
||||||
|
|
||||||
|
six_hours_ago = current_hour_start - timedelta(hours=6)
|
||||||
|
seven_hours_ago = current_hour_start - timedelta(hours=7)
|
||||||
|
|
||||||
|
sessions = models.Session.objects.all()
|
||||||
|
reminder_sessions = sessions.filter(
|
||||||
|
datetime__gte=seven_hours_ago,
|
||||||
|
datetime__lt=six_hours_ago,
|
||||||
|
)
|
||||||
|
|
||||||
|
if reminder_sessions.count() == 0:
|
||||||
|
self.stdout.write('No classes found within timeframe, returning')
|
||||||
|
return 0
|
||||||
|
|
||||||
|
self.stdout.write('Found {} sessions between {} and {} mountain time.'.format(
|
||||||
|
reminder_sessions.count(),
|
||||||
|
str(seven_hours_ago),
|
||||||
|
str(six_hours_ago),
|
||||||
|
))
|
||||||
|
|
||||||
|
for session in reminder_sessions:
|
||||||
|
self.stdout.write('Session {} instructor {}:'.format(
|
||||||
|
str(session),
|
||||||
|
session.instructor.username,
|
||||||
|
))
|
||||||
|
|
||||||
|
if session.is_cancelled:
|
||||||
|
self.stdout.write(' Is cancelled, skipping.')
|
||||||
|
continue
|
||||||
|
|
||||||
|
if session.course.id in [317, 273, 413]:
|
||||||
|
self.stdout.write(' Is members meeting or cleanup, skipping.')
|
||||||
|
continue
|
||||||
|
|
||||||
|
if session.course.tags in ['Event', 'Outing']:
|
||||||
|
self.stdout.write(' Is only outing or event, skipping.')
|
||||||
|
continue
|
||||||
|
|
||||||
|
if session.students.count() == 0:
|
||||||
|
self.stdout.write(' Class is empty, skipping.')
|
||||||
|
continue
|
||||||
|
|
||||||
|
if session.students.filter(attendance_status='Attended').count() > 0:
|
||||||
|
self.stdout.write(' Instructor already marked attendance, skipping.')
|
||||||
|
continue
|
||||||
|
|
||||||
|
self.stdout.write(' Emailing {} {}:'.format(session.instructor.username, session.instructor.email))
|
||||||
|
|
||||||
|
utils.alert_tanner('Attendance reminder {} for {} {}'.format(
|
||||||
|
str(session),
|
||||||
|
session.instructor.username,
|
||||||
|
session.instructor.email,
|
||||||
|
))
|
||||||
|
|
||||||
|
self.stdout.write(' Sent attendance reminder email.')
|
||||||
|
|
||||||
|
count += 1
|
||||||
|
|
||||||
|
return count
|
||||||
|
|
||||||
|
|
||||||
def handle(self, *args, **options):
|
def handle(self, *args, **options):
|
||||||
self.stdout.write('{} - Beginning hourly tasks'.format(str(now())))
|
self.stdout.write('{} - Beginning hourly tasks'.format(str(now())))
|
||||||
|
@ -100,7 +169,10 @@ class Command(BaseCommand):
|
||||||
self.stdout.write('Generated stats')
|
self.stdout.write('Generated stats')
|
||||||
|
|
||||||
count = self.send_class_reminders()
|
count = self.send_class_reminders()
|
||||||
self.stdout.write('Sent {} reminders'.format(count))
|
self.stdout.write('Sent {} class reminders'.format(count))
|
||||||
|
|
||||||
|
count = self.send_attendance_reminders()
|
||||||
|
self.stdout.write('Sent {} attendance reminders'.format(count))
|
||||||
|
|
||||||
self.stdout.write('Completed tasks in {} s'.format(
|
self.stdout.write('Completed tasks in {} s'.format(
|
||||||
str(time.time() - start)[:4]
|
str(time.time() - start)[:4]
|
||||||
|
|
Loading…
Reference in New Issue
Block a user