Example #1
0
def check_in(student_id, class_id):
    """Checkin student to a class"""

    try:
        student = Student.get(Student.id == student_id)
    except Exception:
        cprint('Student Id Not Found', 'red')
        return
    try:
        class_ = Class_.get(Class_.id == class_id)
    except Exception:
        cprint('Class Not Found', 'red')
        return

    if student.checked_in:
        cprint("{} is already checked in".format(
            student.student_name), 'red', 'on_grey')
    elif not class_.session:
        cprint("{} is not in session".format(
            class_.class_name), 'red', 'on_grey')
    else:
        # Add a check in entry to check_ins table
        check_in = Checkin.create(
            student=student, class_=class_, status=1)
        check_in.save()

        # Set the student's check_in status to true
        qry = Student.update(checked_in=1).where(Student.id == student_id)
        qry.execute()

        cprint("Checked in {} to {} class".format(
            student.student_name, class_.class_name), 'green', 'on_grey')