Пример #1
0
def is_appointment_today(today_date, app):
    if not app.is_active:
        return False
    # Check appointments that are one day
    if app.end_date == "" and app.days_of_week == "":
        if timeslotHelp.date_string_to_object(app.start_date).date() == today_date:
            return True

    else:
        # Check recurring appointments
        # Get the day of week from the today_date
        if app.end_date != "":
            # Add if on a recurring day of week and not past the end date but today is after the start date
            if str(today_date.weekday() + 1) in timeslotHelp.day_letters_to_day_nums(app.days_of_week):
                if (
                    timeslotHelp.date_string_to_object(app.end_date).date()
                    >= today_date
                    >= timeslotHelp.date_string_to_object(app.start_date).date()
                ):
                    return True

        # Check never ending appointments
        else:
            # Add if on the day of week
            if str(today_date.weekday() + 1) in timeslotHelp.day_letters_to_day_nums(app.days_of_week):
                return True

    return False
Пример #2
0
def prev_next_week():
    current_teacher = request.form['current_teacher']

    # They push next
    if request.form['type'] == "next":
        current_date = timeslotHelp.date_string_to_object(request.form['date']).date()
        new_date = current_date + timedelta(7)
        # Send them to the next day
        return redirect(url_for('.filter_teachers', date=new_date, current_teacher=current_teacher))
    else:
        current_date = timeslotHelp.date_string_to_object(request.form['date']).date()
        new_date = current_date - timedelta(7)
        # Send them to the previous day
        return redirect(url_for('.filter_teachers', date=new_date, current_teacher=current_teacher))
Пример #3
0
def print_full_schedule(current_day):
    wb = xlwt.Workbook()
    ws = wb.add_sheet(current_day + ' Schedule')

    all_teachers = models.Teacher.query.all()

    # Write the header
    ws.write(0, 3, current_day)
    for idx, teacher in enumerate(all_teachers):
        ws.write(1, idx + 1, teacher.name)

    # Write the timeslots
    timeslots = timeslotHelp.get_timeslots()
    for idx, timeslot in enumerate(timeslots):
        ws.write(idx * 5 + 2, 0, timeslot)

    display_appointments = util.build_display_appointments(timeslotHelp.date_string_to_object(current_day).date(),
                                                           all_teachers)

    # Print out each appointment
    for timeslot in range(0, 20):
        for count in range(0, 5):
            for teacherNum in range(0, len(all_teachers)):
                if display_appointments[teacherNum][timeslot][count] is not None:
                    ws.write(timeslot * 5 + count + 2, teacherNum + 1, display_appointments[teacherNum][timeslot][count].tutee.first_name + ' ' +
                             display_appointments[teacherNum][timeslot][count].tutee.last_name + '-' +
                             display_appointments[teacherNum][timeslot][count].service.name)

    return wb
Пример #4
0
def prev_next_day():
    # They push next
    if request.form['type'] == "next":
        current_date = timeslotHelp.date_string_to_object(request.form['date'])
        if current_date.date().weekday() == 4:
            new_date = current_date + timedelta(3)
        else:
            new_date = current_date + timedelta(1)
        # Send them to the next day
        return redirect(url_for('.home', date=new_date, teacherset=request.form['teacherset']))
    else:
        current_date = timeslotHelp.date_string_to_object(request.form['date'])
        if current_date.date().weekday() == 0:
            new_date = current_date - timedelta(3)
        else:
            new_date = current_date - timedelta(1)
        # Send them to the previous day
        return redirect(url_for('.home', date=new_date, teacherset=request.form['teacherset']))
Пример #5
0
def remove_old_appointments():
    appointments = models.Appointment.query.filter_by(is_active=True).all()
    today_date = datetime.datetime.now().date()

    for app in appointments:
        # Check one day appointments
        if (
            app.end_date == ""
            and app.days_of_week == ""
            and timeslotHelp.date_string_to_object(app.start_date).date() < today_date
        ):
            app.is_active = False
        # Check recurring appointments
        if (
            app.end_date != ""
            and app.days_of_week != ""
            and timeslotHelp.date_string_to_object(app.end_date).date() < today_date
        ):
            app.is_active = False
        db.session.commit()
Пример #6
0
def is_teacher_appointment_absent(date, app, teacher_absences):
    absent = False

    for absence in teacher_absences:
        # is absent if there is an absence with that appointment on that day and for the same appointment
        if (
            date == timeslotHelp.date_string_to_object(absence.date_of_absence).date()
            and app.id == absence.appointment_id
        ):
            absent = True
            break

    return absent
Пример #7
0
def get_appointments_at_date_time(date, timeslot):
    timeslot = str(timeslot)
    db_appointments = models.Appointment.query.filter_by(is_active=True).all()

    all_absences = models.Absence.query.all()
    all_makeups = [app for app in db_appointments if app.is_makeup == True]

    # Remove appointments not at the specified timeslot and day
    current_appointments = [
        app
        for app in db_appointments
        if timeslot in app.times.split(" ")
        and is_appointment_today(timeslotHelp.date_string_to_object(date).date(), app)
    ]

    return_appointments = list()
    for app in current_appointments:
        if not is_absent(timeslotHelp.date_string_to_object(date).date(), app, all_absences) and not is_rescheduled(
            timeslotHelp.date_string_to_object(date).date(), app, all_makeups
        ):
            return_appointments.append(app)
    return return_appointments
Пример #8
0
def is_teacher_appointment_rescheduled(date, app, teacher_makeups):
    rescheduled = False

    for makeup in teacher_makeups:
        # is rescheduled if there is an makeup for that student with the old time, date, and teacher
        if (
            app.id != makeup.id
            and app.tutee == makeup.tutee
            and date == timeslotHelp.date_string_to_object(makeup.old_date).date()
            and app.times == makeup.old_time
        ):
            rescheduled = True
            break

    return rescheduled
Пример #9
0
def is_absent(today_date, app, all_absences):
    if app.appointments is None or app.tutee is None or app.service is None:
        return False
    absent = False

    for absence in all_absences:
        # is absent if there is an absence with that appointment on that day and for the same appointment
        if (
            today_date == timeslotHelp.date_string_to_object(absence.date_of_absence).date()
            and app.id == absence.appointment_id
        ):
            absent = True
            break

    return absent
Пример #10
0
def is_rescheduled(today_date, app, all_makeups):
    if app.appointments is None or app.tutee is None or app.service is None:
        return False
    rescheduled = False

    for makeup in all_makeups:
        # is rescheduled if there is an makeup for that student with the old time, date, and teacher
        if (
            app.id != makeup.id
            and app.tutee == makeup.tutee
            and today_date == timeslotHelp.date_string_to_object(makeup.old_date).date()
            and app.appointments.name == makeup.old_teacher
            and app.times == makeup.old_time
        ):
            rescheduled = True
            break

    return rescheduled
Пример #11
0
def mark_appointment_absent(form):
    # Get the form data
    today_date = timeslotHelp.date_string_to_object(form['today_date']).date()
    app_id = int(form['app_id'])
    start_time = timeslotHelp.time_string_to_timeslot_num(form['start_time'])
    end_time = timeslotHelp.time_string_to_timeslot_num(form['end_time'])
    timeslots = range(start_time, end_time)

    app_to_mark_absent = models.Appointment.query.filter_by(id=app_id).first()

    # Delete
    if app_to_mark_absent is not None:
        new_absence = models.Absence(date_of_absence=today_date, appointment_id=app_id,
                                     time_absent=timeslotHelp.timeslot_num_to_timeslot_string(timeslots))
        db.session.add(new_absence)
        db.session.commit()
        flash("Appointment has been successfully marked absent.")
    # Need to have a confirmation message
    return redirect(url_for('.home'))
Пример #12
0
    def validate(self):

        teacher_object = models.Teacher.query.filter_by(name=self.new_teacher.data).first()
        if teacher_object is None:
            return 'Not a valid teacher'

        # if timeslotHelp.time_string_to_timeslot_num(self.end_time.data) <= \
        #    timeslotHelp.time_string_to_timeslot_num(self.start_time.data):
        #     return 'Please make sure the end time is after the start time'
        #
        # if self.end_date.data != '' and self.end_date.data < self.start_date.data:
        #     return 'Please make sure the end date is after the start time'

        # Make sure that the appointment is not in the past
        if self.new_date.data == '' or \
           timeslotHelp.date_string_to_object(self.new_date.data).date() < (datetime.datetime.now() - datetime.timedelta(hours=8)).date():
            return 'Please enter a valid date'

        self.teacher_object = teacher_object

        return ''
Пример #13
0
def delete_appointment(form):
    # Get the form data
    today_date = timeslotHelp.date_string_to_object(form['today_date']).date()
    selected_row = int(form['row'])
    selected_col = int(form['col'])

    # If there is a teacher set, then we are coming from the home page
    if form['teacher_set'] != '':
        teacher_set = int(form['teacher_set'])

        teachers = util.build_display_teachers(teacher_set)
        display_appointments = util.build_display_appointments(today_date, teachers)
    # TODO Refactor this to make it better for building teacher display appointment
    # Else we are on a teacher page
    else:
        current_teacher = models.Teacher.query.filter_by(name=request.form['teacher']).first()

        # Get the week that the current day is in
        day_of_week = today_date.weekday()
        dates_of_week = list()

        for day in range(0, day_of_week + 1):
            dates_of_week.append(today_date - timedelta(days=day))

        for day in range(day_of_week + 1, 5):
            dates_of_week.append(today_date + timedelta(days=day - day_of_week))

        dates_of_week.sort()
        display_appointments = util.build_display_teacher_appointments(dates_of_week, current_teacher)

    # Get the appointment that was selected from the table
    app_to_delete = display_appointments[selected_col][selected_row / 5][selected_row % 5]

    # Delete
    if app_to_delete is not None:
        db.session.delete(app_to_delete)
        db.session.commit()
        flash("Appointment has been successfully deleted.")
    # Need to have a confirmation message
    return redirect(url_for('.home'))
Пример #14
0
def filter_teachers():
    # Get the list of appointments for the teacher on that week
    make_form = forms.MakeAppointmentForm(request.form)
    edit_form = forms.EditAppointmentForm(request.form)
    days_of_week = 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'

    # Get the teacher and the current date
    if len(request.args) > 0:
        today_string = request.args['date']
        current_teacher = models.Teacher.query.filter_by(name=request.args['current_teacher']).first()
    # elif len(request.args) == 2:
    #     today_date = request.args['date']
    #     today_date = datetime.datetime.strptime(today_date, "%Y-%m-%d %H:%M:%S").date()
    else:
        current_teacher = models.Teacher.query.filter_by(name=request.form['teacher']).first()
        today_string = request.form['today_date']

    # Get the week that the current day is in
    today_date = timeslotHelp.date_string_to_object(today_string).date()
    day_of_week = today_date.weekday()
    dates_of_week = list()

    for day in range(0, day_of_week + 1):
        dates_of_week.append(today_date - timedelta(days=day))

    for day in range(day_of_week + 1, 5):
        dates_of_week.append(today_date + timedelta(days=day - day_of_week))

    dates_of_week.sort()
    services = models.Service.query.all()
    all_teachers = models.Teacher.query.all()
    display_appointments = util.build_display_teacher_appointments(dates_of_week, current_teacher)

    return render_template('teacher_week_home.html',
                           teachers=all_teachers, services=services, display_appointments=display_appointments,
                           today=today_date.strftime('%A'), today_date=today_date, dates_of_week=dates_of_week,
                           make_form=make_form, current_appointment=None, days_of_week=days_of_week,
                           edit_form=edit_form, all_teachers=all_teachers, current_teacher=current_teacher)
Пример #15
0
    def validate(self):
        rv = Form.validate(self)
        if not rv:
            # Handle situation where the end date is disabled and gives a None
            if self.appointmentEndType.data != 'None':
                return 'Invalid Appointment Information'

        student_object = models.Student.query.filter_by(fullname_lower=self.student.data.lower()).first()
        if student_object is None:
            return 'Not a valid student'
        teacher_object = models.Teacher.query.filter_by(name=self.teacher.data).first()
        if teacher_object is None:
            return 'Not a valid teacher'
        service_object = models.Service.query.filter_by(name=self.service.data).first()
        if service_object is None:
            return 'Not a valid service'

        # Make sure the start and end date and start and end times are in the right order
        if timeslotHelp.time_string_to_timeslot_num(self.end_time.data) <= \
           timeslotHelp.time_string_to_timeslot_num(self.start_time.data):
            return 'Please make sure the end time is after the start time'

        if self.end_date.data != '' and self.end_date.data < self.start_date.data:
            return 'Please make sure the end date is after the start time'

        days_of_week = ''

        monday = self.monday.data
        if monday:
            days_of_week += 'M'
        tuesday = self.tuesday.data
        if tuesday:
            days_of_week += 'T'
        wednesday = self.wednesday.data
        if wednesday:
            days_of_week += 'W'
        thursday = self.thursday.data
        if thursday:
            days_of_week += 'R'
        friday = self.friday.data
        if friday:
            days_of_week += 'F'

        if self.recurringType.data == 'doRecur' and days_of_week == '':
            return 'Select which days the appointment will be on.'

        if self.recurringType.data == 'doRecur' and self.appointmentEndType.data == 'date' and self.end_date.data == '':
            return 'Enter an end date for a recurring appointment.'

        # Make sure that the appointment is not in the past
        # One day appointments
        if self.end_date.data == '' and days_of_week == '' and \
           timeslotHelp.date_string_to_object(self.start_date.data).date() < (datetime.datetime.now() - datetime.timedelta(hours=8)).date():
            return 'Please make sure your appointment is not scheduled in the past'

        # Recurring appointments
        if self.end_date.data != '' and days_of_week != '' and \
           timeslotHelp.date_string_to_object(self.end_date.data).date() < (datetime.datetime.now() - datetime.timedelta(hours=8)).date():
            return 'Please make sure your appointment is not scheduled in the past'

        self.student_object = student_object
        self.teacher_object = teacher_object
        self.service_object = service_object
        self.days_of_week = days_of_week

        return ''
Пример #16
0
def print_schedule():
    response = Response()
    response.status_code = 200

    # First thing it gets is the type, 0 for day of week, 1 for week of teacher
    print_type = int(request.form['print_type'])
    if print_type == 0:
        # We need to get the current day to output the full schedule for that day
        current_day = request.form['day']
        filename = current_day + ' Schedule.xls'

        workbook = excel_lib.print_full_schedule(current_day)
    else:
        # Get the current teacher and the week that they are on
        teacher = request.form['teacher']

        current_week = request.form['week']

        # Get the week that the current day is in
        today_date = timeslotHelp.date_string_to_object(current_week).date()
        day_of_week = today_date.weekday()
        dates_of_week = list()

        for day in range(0, day_of_week + 1):
            dates_of_week.append(today_date - timedelta(days=day))

        for day in range(day_of_week + 1, 5):
            dates_of_week.append(today_date + timedelta(days=day - day_of_week))

        dates_of_week.sort()

        filename = teacher + ' Schedule.xls'

        workbook = excel_lib.print_teacher_schedule(teacher, dates_of_week)

    output = StringIO.StringIO()
    workbook.save(output)
    response.data = output.getvalue()

    mimetype_tuple = mimetypes.guess_type(filename)

    response_headers = Headers({
        'Pragma': "public",  # required,
        'Expires': '0',
        'Cache-Control': 'must-revalidate, post-check=0, pre-check=0',
        'Cache-Control': 'private',  # required for certain browsers,
        'Content-Type': mimetype_tuple[0],
        'Content-Disposition': 'attachment; filename=\"%s\";' % filename,
        'Content-Transfer-Encoding': 'binary',
        'Content-Length': len(response.data)
    })

    if not mimetype_tuple[1] is None:
        response.update({
            'Content-Encoding': mimetype_tuple[1]
        })

    response.headers = response_headers

    response.set_cookie('fileDownload', 'true', path='/')

    return response