Beispiel #1
0
def log_end(class_id):
    """End class session"""

    try:
        class_instance = Class_.get(Class_.id == class_id)
    except Exception:
        cprint('Student Not Found', 'red')
        return

    end = time.time()

    if not class_instance.session:
        cprint("{} is not in session".format(
            class_instance.class_name), 'red')
    else:
        # Update end time with current time
        update_end_time = Class_.update(
            end_time=end).where(Class_.id == class_id)
        update_end_time.execute()

        # Set class session to closed
        closed = Class_.update(session=0).where(Class_.id == class_id)
        closed.execute()

        cprint("{0} class has ended".format(
            class_instance.class_name), 'green', 'on_grey')

        # Checkout all students in the class
        for entry in Checkin.select().where(Checkin.class__id == class_id, Checkin.status == 1):
            # set student checked_in 0
            qry = entry.student.update(checked_in=0)
            qry.execute()
            # s_qry.execute()

        cprint("Checked out all students", 'green', 'on_grey')
Beispiel #2
0
def students_log(class_id):
    """List all students that have ever attended a class"""

    try:
        log = Checkin.select().distinct().where(Checkin.class__id == class_id)
    except Exception:
        cprint("Student not found", 'red')
        return

    table = []
    headers = ["Id", "Student"]
    for item in log:
        table.append([item.student.id, item.student.student_name])
    print(tabulate(table, headers, tablefmt="fancy_grid"))
Beispiel #3
0
def list_classes():
    """List all classes"""

    cprint("List of all classes:", 'cyan', 'on_grey')
    table = []
    headers = ["Id", "Name", "In Session", "Students"]
    for class_ in Class_.select():
        if class_.session:
            n = Checkin.select().where((Checkin.class__id == class_.id)
                                       and (Checkin.status == 1))
            count = n.count()
        else:
            count = ""
        table.append([class_.id, class_.class_name, class_.session, count])
    print(tabulate(table, headers, tablefmt="fancy_grid"))
Beispiel #4
0
def list_students():
    """List all students"""

    # cprint(figlet_format('List of all students:'),
    #       'green', attrs=['bold'])
    cprint("List of all students:", 'cyan', 'on_grey')
    table = []
    headers = ["Id", "Name", "Checked In", "Class"]
    for student in Student.select():
        if student.checked_in:
            sc = Checkin.select().where(Checkin.student_id ==
                                        student.id and Checkin.status == 1).get()
            c = sc.class_.class_name
        else:
            c = ""
        table.append(
            [student.id, student.student_name, student.checked_in, c])
    print(tabulate(table, headers, tablefmt="fancy_grid"))
Beispiel #5
0
def classes_log(student_id):
    """List all classes a student has ever attended"""

    try:
        log = Checkin.select().distinct().where(Checkin.student_id == student_id)
    except Exception:
        cprint("Student not found", 'red')
        return

    table = []
    added = []
    headers = ["Id", "class"]

    for item in log:
        if item.id not in added:
            table.append([item.class_.id, item.class_.class_name])
        else:
            pass
        added.append(item.id)
    print(tabulate(table, headers, tablefmt="fancy_grid"))