示例#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 import_excel(inputfile):
    # Get all of the db data for reference
    courses = models.Course.query.all()
    classrooms = models.Location.query.all()
    instructors = models.Instructor.query.all()

    wb = xlrd.open_workbook(file_contents=inputfile.read())
    sh = wb.sheet_by_index(0)

    # Start off by getting the semester and creating a schedule object to associate with the semester if one is not
    # made already
    current_row = sh.row_values(1)
    semester_string = current_row[6]
    semester_string = semester_string.split(' ')
    if semester_string[0] == "SPRING":
        current_semester = 'spring'
    elif semester_string[0] == "FALL":
        current_semester = 'fall'
    else:
        current_semester = 'summer'
    current_year = semester_string[1]
    current_schedule = models.Schedule.query.filter_by(semester=current_semester, year=current_year).first()

    if current_schedule is None:
        current_schedule = models.Schedule(semester=current_semester, year=current_year)
        db.session.add(current_schedule)
        db.session.commit()
        current_schedule = models.Schedule.query.filter_by(semester=current_semester, year=current_year).first()
    else:
        # For now, just have it delete all the sections for the current semester
        models.Section.query.filter_by(schedule_id=current_schedule.id).delete()

    # Iterate through all of the rows that contain classes, starting at row 5
    for rownum in range(5, sh.nrows):
        print "Importing the", rownum, " row"
        current_row = sh.row_values(rownum)

        # TODO I will need to add in these other things at the end eventually
        # Stop before tutoring
        if current_row[3] == '' and current_row[4] == '' and current_row[5] == '' and current_row[6] == '':
            return

        # If the course title does not exist, create it and add to database
        exists = False
        units = 0
        if current_row[4] != '' and current_row[4] != ' ':
            units = current_row[4]
        if current_row[3] != 'Lab for above':
            for course in courses:
                if current_row[1] == course.code:
                    exists = True
            if not exists:
                new_course = models.Course(name=current_row[3], code=current_row[1], units=units)
                db.session.add(new_course)
                courses.append(new_course)

        else:
            # Also add in labs that are not present yet
            lab_code = current_row[1] + 'L'
            for course in courses:
                if lab_code == course.code:
                    exists = True
            if not exists:
                new_course = models.Course(name=current_row[3], code=lab_code, units=units)
                db.session.add(new_course)
                courses.append(new_course)

        # Repeat for instructors and classrooms
        if current_row[5] != 'TBD' and current_row[5] != 'Staff':
            exists = False
            for instructor in instructors:
                if current_row[5] == instructor.last_name + ', ' + instructor.first_name:
                    exists = True
            if not exists:
                prof_name = current_row[5].split(', ')
                new_instructor = models.Instructor(first_name=prof_name[1], last_name=prof_name[0],
                                                   school_id=current_row[6])
                db.session.add(new_instructor)
                instructors.append(new_instructor)

        exists = False
        for classroom in classrooms:
            if current_row[12] == classroom.name:
                exists = True
        if not exists:
            new_location = models.Location(name=current_row[12])
            db.session.add(new_location)
            classrooms.append(new_location)

        db.session.commit()

        # Now we can start adding the sections to the schedule
        current_course = None
        current_instructor = None
        current_location = None

        # TODO Need to handle when there is an importing error and there is no current class or teacher
        if current_row[3] == 'Lab for above':
            code = current_row[1] + 'L'
        else:
            code = current_row[1]
        for course in courses:
            if course.code == code:
                current_course = course

        for instructor in instructors:
            if instructor.last_name + ', ' + instructor.first_name == current_row[5]:
                current_instructor = instructor

        for location in classrooms:
            if location.name == current_row[12]:
                current_location = location

        num_students = 0
        if current_row[8] != '' and current_row[8] != 'TBD':
            num_students = int(current_row[8])

        # Get the notes
        notes = current_row[13]

        # Catch an error where there is not a current instructor etc
        if current_course is None:
            flash('Error importing row' + str(rownum) + '.')
        else:
            if current_instructor is None and current_location is None:
                new_section = models.Section(section_letter=current_row[2], num_students=num_students,
                                             course_id=current_course.id, times=
                                             timeslotHelp.timeslot_chunk_to_timeslot_nums(current_row[10]), days=
                                             timeslotHelp.day_letters_to_day_nums(current_row[9]),
                                             schedule_id=current_schedule.id, notes=notes)
            elif current_instructor is not None and current_location is None:
                new_section = models.Section(section_letter=current_row[2], num_students=num_students, instructor_id=
                                             current_instructor.id, course_id=current_course.id, times=
                                             timeslotHelp.timeslot_chunk_to_timeslot_nums(current_row[10]), days=
                                             timeslotHelp.day_letters_to_day_nums(current_row[9]),
                                             schedule_id=current_schedule.id, notes=notes)
            elif current_instructor is None and current_location is not None:
                new_section = models.Section(section_letter=current_row[2], num_students=num_students,
                                             course_id=current_course.id, location_id=
                                             current_location.id, times=
                                             timeslotHelp.timeslot_chunk_to_timeslot_nums(current_row[10]), days=
                                             timeslotHelp.day_letters_to_day_nums(current_row[9]),
                                             schedule_id=current_schedule.id, notes=notes)
            else:
                new_section = models.Section(section_letter=current_row[2], num_students=num_students, instructor_id=
                                             current_instructor.id, course_id=current_course.id, location_id=
                                             current_location.id, times=
                                             timeslotHelp.timeslot_chunk_to_timeslot_nums(current_row[10]), days=
                                             timeslotHelp.day_letters_to_day_nums(current_row[9]),
                                             schedule_id=current_schedule.id, notes=notes)

            db.session.add(new_section)
        db.session.commit()
    return
示例#3
0
 def app_contain_day(app, day):
     return day in timeslotHelp.day_letters_to_day_nums(app.days_of_week)