2020-06-05 01:22:26 +00:00
|
|
|
import django, sys, os
|
|
|
|
os.environ['DJANGO_SETTINGS_MODULE'] = 'apiserver.settings'
|
|
|
|
django.setup()
|
|
|
|
|
|
|
|
import datetime
|
|
|
|
import json
|
2020-06-05 03:43:56 +00:00
|
|
|
from django.utils.timezone import now, pytz
|
2020-06-05 01:22:26 +00:00
|
|
|
from apiserver.api import models, utils
|
|
|
|
|
|
|
|
# Member orientation
|
|
|
|
print("Updating member orientation dates")
|
|
|
|
sessions = models.Session.objects.filter(course = 249)
|
|
|
|
|
2020-06-05 03:29:32 +00:00
|
|
|
def get_member(obj):
|
|
|
|
# same as in serialzers.py -> get_cards for example
|
|
|
|
if obj.user:
|
|
|
|
member = obj.user.member
|
|
|
|
else:
|
|
|
|
member = models.Member.objects.get(id=obj.member_id)
|
|
|
|
return member
|
|
|
|
|
|
|
|
|
2020-06-05 01:22:26 +00:00
|
|
|
for session in sessions:
|
|
|
|
students = models.Training.objects.filter(session = session)
|
|
|
|
for student in students:
|
2020-06-05 03:29:32 +00:00
|
|
|
if student.attendance_status == "Attended":
|
|
|
|
member = get_member(student)
|
2020-06-05 01:22:26 +00:00
|
|
|
if not member.orientation_date:
|
2020-06-05 03:43:56 +00:00
|
|
|
member.orientation_date = session.datetime.astimezone(pytz.timezone('America/Edmonton')).date()
|
2020-06-05 01:22:26 +00:00
|
|
|
member.save()
|
|
|
|
|
|
|
|
# Lathe
|
|
|
|
print("Updating lathe training dates")
|
|
|
|
sessions = models.Session.objects.filter(course = 281)
|
|
|
|
|
|
|
|
for session in sessions:
|
|
|
|
students = models.Training.objects.filter(session = session)
|
|
|
|
for student in students:
|
2020-06-05 03:29:32 +00:00
|
|
|
if student.attendance_status == "Attended":
|
|
|
|
member = get_member(student)
|
2020-06-05 01:22:26 +00:00
|
|
|
if not member.lathe_cert_date:
|
2020-06-05 03:43:56 +00:00
|
|
|
member.lathe_cert_date = session.datetime.astimezone(pytz.timezone('America/Edmonton')).date()
|
2020-06-05 01:22:26 +00:00
|
|
|
member.save()
|
|
|
|
|
|
|
|
# Manual Mill
|
|
|
|
print("Updating mill training dates")
|
|
|
|
sessions = models.Session.objects.filter(course = 283)
|
|
|
|
|
|
|
|
for session in sessions:
|
|
|
|
students = models.Training.objects.filter(session = session)
|
|
|
|
for student in students:
|
2020-06-05 03:29:32 +00:00
|
|
|
if student.attendance_status == "Attended":
|
|
|
|
member = get_member(student)
|
2020-06-05 01:22:26 +00:00
|
|
|
if not member.mill_cert_date:
|
2020-06-05 03:43:56 +00:00
|
|
|
member.mill_cert_date = session.datetime.astimezone(pytz.timezone('America/Edmonton')).date()
|
2020-06-05 01:22:26 +00:00
|
|
|
member.save()
|
|
|
|
|
|
|
|
|
|
|
|
# Woodworking tools
|
|
|
|
print("Updating woodworking training dates")
|
|
|
|
sessions = models.Session.objects.filter(course = 261)
|
|
|
|
|
|
|
|
for session in sessions:
|
|
|
|
students = models.Training.objects.filter(session = session)
|
|
|
|
for student in students:
|
2020-06-05 03:29:32 +00:00
|
|
|
if student.attendance_status == "Attended":
|
|
|
|
member = get_member(student)
|
2020-06-05 01:22:26 +00:00
|
|
|
if not member.wood_cert_date:
|
2020-06-05 03:43:56 +00:00
|
|
|
member.wood_cert_date = session.datetime.astimezone(pytz.timezone('America/Edmonton')).date()
|
2020-06-05 01:22:26 +00:00
|
|
|
member.save()
|
|
|
|
|
|
|
|
print('Done.')
|