Exemple #1
0
def dashboard():
    """
    Student Dashboard.
    """
    # Get the current time.
    now = datetime.now()
    # Select the future lessons.
    future_lessons = select_future_lessons(current_user)
    # Select all the past lessons, that were attended. (Limit to 5)
    attended_lessons_assoc = select_lessons_assoc(
        current_user,
        max_date=now,
        attendance_codes=('A', 'L'),
        date_order_asc=True,
        limit=5
    )
    # Select all the past lessons, that have not been recorded.
    unknown_lessons_assoc = select_lessons_assoc(
        current_user,
        max_date=now,
        attendance_code=None,
        date_order_asc=True
    )
    # Render the dashboard template, passing in the lessons selected from the database.
    return render_template(
        'student/dashboard.html', lessons=future_lessons,
        attended_lessons_assoc=attended_lessons_assoc, unknown_lessons_assoc=unknown_lessons_assoc
    )
Exemple #2
0
def attendance():
    """
    View Attendance.
    """
    # Get the current year.
    year = datetime.now().year
    # Create a datetime object for the 1st Jan this year.
    beginning_of_year = datetime(year, 1, 1)

    # All attended.
    lessons_attended_assoc = select_lessons_assoc(
        current_user, min_date=beginning_of_year, attendance_code='A'
    )
    # All absent.
    lessons_absent_assoc = select_lessons_assoc(
        current_user, min_date=beginning_of_year, attendance_codes=('P', 'N')
    )
    # All late.
    lessons_late_assoc = select_lessons_assoc(
        current_user, min_date=beginning_of_year, attendance_code='L'
    )

    # Calculate percentages of attendance.
    # Total number of lessons.
    total_number_of_lessons = len(lessons_attended_assoc) + \
        len(lessons_absent_assoc)+len(lessons_late_assoc)
    # Ensure the total number of lessons is greater than zero,
    # in order to stop division by zero error.
    if total_number_of_lessons > 0:
        # Number present, Number Absent, Number Late.
        attendance_statistics = [
            len(lessons_attended_assoc)*100/total_number_of_lessons,
            len(lessons_absent_assoc)*100/total_number_of_lessons,
            len(lessons_late_assoc)*100/total_number_of_lessons
        ]
    else:
        # All statistics will be zero.
        attendance_statistics = [0, 0, 0]
    # Render the template passing all of the data selected from the database.
    return render_template(
        'student/attendance.html', lessons_attended_assoc=lessons_attended_assoc,
        lessons_late_assoc=lessons_late_assoc, lessons_absent_assoc=lessons_absent_assoc,
        attendance_statistics=attendance_statistics
    )
Exemple #3
0
def view_lesson(lesson_id):
    """
    View a single Lesson.
    """
    # Get the UserLessonAssociation for the current and
    # the given lesson id. (So we can also display attendance etc.)
    assoc = select_lessons_assoc(current_user, lesson_id=lesson_id, single=True)
    # Ensure the assoc exists.
    if not assoc:
        # Abort with 404 error code.
        abort(404)
    # Render the view lesson template and pass in the association and the lesson object.
    return render_template(
        'student/view_lesson.html', lesson=assoc.lesson, assoc=assoc
    )