コード例 #1
0
ファイル: views.py プロジェクト: jakemalley/peri2organise
def attendance():
    """
    Display all lessons attendance can be recorded for.
    """
    # Create new form objects for minimum and maximum dates.
    select_date_form = SelectMinMaxDateForm()

    if request.method == 'POST' and select_date_form.validate_on_submit():
        # Form was submitted and is valid, filter by dates.
        no_attendance_recorded = Lesson.query.filter(Lesson.attendance_recorded == False).filter(
            Lesson.lesson_datetime >= select_date_form.min_date.data
        ).filter(
            Lesson.lesson_datetime <= select_date_form.max_date.data + timedelta(days=1)
        ).all()

    else:
        # Select all lessons with recorded attendance.
        no_attendance_recorded = Lesson.query.filter(Lesson.attendance_recorded == False).all()

    # Render the attendance template.
    return render_template(
        'staff/attendance.html',
        no_attendance_recorded=no_attendance_recorded,
        select_date_form=select_date_form
    )
コード例 #2
0
ファイル: views.py プロジェクト: jakemalley/peri2organise
def attendance():
    """
    Display all lessons attendance can be recorded for.
    """
    # Create new form objects for minimum and maximum dates.
    select_date_form = SelectMinMaxDateForm()

    if request.method == 'POST' and select_date_form.validate_on_submit():
        # Form was submitted and is valid, filter by dates.
        no_attendance_recorded = select_lessons(
            current_user, attendance_recorded=False,
            min_date=select_date_form.min_date.data, max_date=select_date_form.max_date.data,
            order_by=Lesson.lesson_datetime.asc()
        )
    else:
        # Select all lessons with recorded attendance.
        no_attendance_recorded = select_lessons(
            current_user, attendance_recorded=False,
            order_by=Lesson.lesson_datetime.asc()
        )

    # Render the attendance template.
    return render_template(
        'tutor/attendance.html',
        no_attendance_recorded=no_attendance_recorded,
        select_date_form=select_date_form
    )
コード例 #3
0
ファイル: views.py プロジェクト: jakemalley/peri2organise
def timesheet():
    """
    Calculate the total amount of lesson time.
    """
    # Create new form objects for minimum and maximum dates.
    select_date_form = SelectMinMaxDateForm()
    # Set lessons and hours worked to None.
    time_sheet_lessons = time_sheet_time = None

    if request.method == 'POST' and select_date_form.validate_on_submit():
        # Set the min and max dates to the dates on the form.
        min_date = select_date_form.min_date.data
        max_date = select_date_form.max_date.data
    else:
        # This month.
        min_date = datetime.now() - timedelta(days=30)
        max_date = datetime.now()
        # Set the form defaults to these dates.
        select_date_form.min_date.default = min_date
        select_date_form.max_date.default = max_date
        # Process the form to update.
        select_date_form.process()

    # Select the lessons
    time_sheet_lessons = generate_timesheet(
        current_user, min_date, max_date
    )

    # Total the seconds worked.
    time_sheet_time = total_time(time_sheet_lessons)

    # Return the template with the data.
    return render_template(
        'tutor/timesheet.html', time_sheet_lessons=time_sheet_lessons,
        time_sheet_time=time_sheet_time, select_date_form=select_date_form
    )