コード例 #1
0
 def create_email_preferences(self, user_id, sub_email_pref,
                              stu_email_pref):
     new_email_prefs = EmailPreferencesTable(
         user_id=user_id,
         subRequestEmail=sub_email_pref,
         studentSignUpEmail=stu_email_pref)
     db_session.add(new_email_prefs)
     db_session.commit()
コード例 #2
0
 def create_user(self, first_name, last_name, username, sub_email_pref,
                 stu_email_pref):
     new_user = UserTable(username=username,
                          firstName=first_name,
                          lastName=last_name,
                          email='{0}@bethel.edu'.format(username),
                          bannedDate=None,
                          deletedAt=None)
     db_session.add(new_user)
     db_session.commit()
     self.create_email_preferences(new_user.id, sub_email_pref,
                                   stu_email_pref)
     return new_user
コード例 #3
0
 def set_user_roles(self, username, roles):
     user = self.get_user_by_username(username)
     for role in roles:
         role_entry = self.get_role_by_name(role)
         # Check if the user already has this role
         role_exists = db_session.query(UserRoleTable)\
             .filter(UserRoleTable.user_id == user.id)\
             .filter(UserRoleTable.role_id == role_entry.id)\
             .one_or_none()
         if role_exists:  # If they do, skip adding it again
             continue
         user_role = UserRoleTable(user_id=user.id, role_id=role_entry.id)
         db_session.add(user_role)
     db_session.commit()
コード例 #4
0
 def create_user(self, username, name):
     first_name = name['0']['firstName']
     last_name = name['0']['lastName']
     email = '{0}@bethel.edu'.format(username)
     user = UserTable(
         username=username,
         email=email,
         firstName=first_name,
         lastName=last_name,
     )
     db_session.add(user)
     db_session.commit()
     user_role = UserRoleTable(user_id=user.id, role_id=4)
     db_session.add(user_role)
     db_session.commit()
コード例 #5
0
 def create_time_slot(self, start_time, end_time, is_active):
     try:
         if self.check_for_existing_schedule(start_time, end_time):
             schedule = db_session.query(ScheduleTable) \
                 .filter(ScheduleTable.startTime == start_time) \
                 .filter(ScheduleTable.endTime == end_time) \
                 .one()
             if schedule.active == 0 and is_active == 1:
                 schedule.active = 1
                 db_session.commit()
                 return True
             else:
                 return False
         new_schedule = ScheduleTable(startTime=start_time,
                                      endTime=end_time,
                                      active=is_active)
         db_session.add(new_schedule)
         db_session.commit()
         return True
     except Exception as e:
         return False
コード例 #6
0
 def begin_walk_in_appointment(self, user, tutor, course, assignment,
                               multilingual):
     if course:
         course_code = course['course_code']
         course_section = course['section']
         prof_name = course['instructor']
         prof_email = course['instructor_email']
         begin_appt = AppointmentsTable(student_id=user.id,
                                        tutor_id=tutor.id,
                                        actualStart=datetime.now(),
                                        profName=prof_name,
                                        profEmail=prof_email,
                                        assignment=assignment,
                                        courseCode=course_code,
                                        courseSection=course_section,
                                        inProgress=1,
                                        dropIn=1,
                                        sub=0,
                                        multilingual=multilingual,
                                        noShow=0,
                                        online=0)
     else:
         begin_appt = AppointmentsTable(student_id=user.id,
                                        tutor_id=tutor.id,
                                        actualStart=datetime.now(),
                                        assignment=assignment,
                                        inProgress=1,
                                        dropIn=1,
                                        sub=0,
                                        multilingual=multilingual,
                                        noShow=0,
                                        online=0)
     db_session.add(begin_appt)
     try:
         db_session.commit()
         return begin_appt
     except Exception as e:
         return False
コード例 #7
0
 def create_tutor_shifts(self, start_date, end_date, multilingual, drop_in,
                         virtual, tutor_ids, days_of_week, time_slots):
     # I honestly hate this but since we have 3 different selects which all can be multiple I think this is the only
     # way we can achieve the desired effect.
     warning = False
     for day in days_of_week:
         for tutor_id in tutor_ids:
             tutor_id = int(tutor_id)
             tutor = self.get_user_by_id(tutor_id)
             if tutor:
                 for time_slot in time_slots:
                     # Splits the time slot into a start time and end time
                     time_slot = time_slot.split('-')
                     start_ts = time_slot[0]
                     # Formats the meridiems to work with datetime
                     start_ts = start_ts.replace('a.m.', "AM")
                     start_ts = start_ts.replace('p.m.', "PM")
                     # Removes whitespace
                     start_ts = start_ts.strip()
                     # Formats the string into a datetime object
                     try:
                         start_ts = datetime.strptime(start_ts, '%I %p')
                     except:
                         start_ts = datetime.strptime(start_ts, '%I:%M %p')
                     end_ts = time_slot[1]
                     # Formats the meridiems to work with datetime
                     end_ts = end_ts.replace('a.m.', "AM")
                     end_ts = end_ts.replace('p.m.', "PM")
                     # Removes whitespace
                     end_ts = end_ts.strip()
                     # Formats the string into a datetime object
                     try:
                         end_ts = datetime.strptime(end_ts, '%I %p')
                     except:
                         end_ts = datetime.strptime(end_ts, '%I:%M %p')
                     appt_date = self.get_first_appointment_date(
                         day, start_date)
                     if appt_date > end_date:
                         return False
                     while appt_date <= end_date:  # Loop through until our session date is after the end date of the term
                         # Updates the datetime object with the correct date
                         start_ts = start_ts.replace(year=appt_date.year,
                                                     month=appt_date.month,
                                                     day=appt_date.day)
                         end_ts = end_ts.replace(year=appt_date.year,
                                                 month=appt_date.month,
                                                 day=appt_date.day)
                         appointment = AppointmentsTable(
                             tutor_id=tutor.id,
                             scheduledStart=start_ts,
                             scheduledEnd=end_ts,
                             inProgress=0,
                             multilingual=multilingual,
                             dropIn=drop_in,
                             online=virtual,
                             sub=0,
                             noShow=0)
                         # This check makes sure only future shifts can be assigned (useful when creating a shift the
                         # day of)
                         if start_ts > datetime.now():
                             appts = self.get_future_tutor_appts(tutor.id)
                             commit = True
                             for appt in appts:
                                 # This check is to make sure the tutor doesn't already have a shift that overlaps
                                 # with the one you are trying to schedule them for
                                 if start_ts <= appt.scheduledStart < end_ts or start_ts < appt.scheduledEnd <= end_ts:
                                     commit = False
                                     break
                             if commit:
                                 db_session.add(appointment)
                                 db_session.commit()
                         else:
                             warning = 'warning'
                         appt_date += timedelta(
                             weeks=1)  # Add a week for next session
     if warning:
         return warning
     return True