def save_schedule(self, user: md.User, schedule: schd.Schedule): """ Saves a schedule binding it to a user into the database. :param user: the user :type user: md.User :param schedule: the schedule :type schedule: schd.Schedule :return: the scheduler, with its id updated... """ if schedule.id is None: # this schedule is not yet saved schd_db = md.Schedule(data=schedule, user=user) schd_db.data.id = schd_db.id self.database.session.commit() return schd_db.data else: # this schedule has already been saved # TODO: control access levels schd_db = user.get_schedule(id=schedule.id) if schd_db is None: raise ScheduleNotOwnedError else: schd_db.update_data(schedule) return schd_db.data
def save_schedule(self, user: md.User, schedule: schd.Schedule, uuid): """ Saves a schedule binding it to a user into the database. :param user: the user :type user: md.User :param schedule: the schedule :type schedule: schd.Schedule :return: the scheduler, with its id updated... """ if schedule.id is None: # this schedule is not yet saved schd = md.Schedule(data=schedule, user=user) schd.data.id = schd.id self.database.session.commit() else: # this schedule has already been saved schd = md.Schedule.query.filter( md.Schedule.id == schedule.id).first() if schd is None: raise ScheduleNotFountError else: schd.update_data(schedule) if user is not None: user_has_schedule = user.get_schedule( id=schedule.id) is not None else: user_has_schedule = False if not user_has_schedule and user is not None: user.add_schedule(schd) # Update the last person to modify the schedule schd.update_last_modified_by(uuid) return schd.data