def add(name, health): if name is None or health not in [AircraftHealth.GOOD, AircraftHealth.BLOCKING, AircraftHealth.NON_BLOCKING]: raise ValueError('Name or Health must be specified correctly') new_item = Aircraft(name=name, health=health) new_item.id = get_timebased_uuid() db_session.add(new_item) db_session.commit() return new_item
def add(name, email, userType): if name is None or email is None or userType not in [ UserType.HUMAN, UserType.AUTOMATED ]: raise ValueError( 'Name, Email and UserType must be specified correctly') new_item = User(name=name, email=email, type=userType) new_item.id = get_timebased_uuid() db_session.add(new_item) db_session.commit() return new_item
def add(user_id, aircraft_id, description, blocked=True): if user_id is None or aircraft_id is None or description is None: raise ValueError( 'user_id, aircraft_id, or description must be specified correctly' ) # Add Maintenance Record new_item = Maintenance(description=description, created=datetime.utcnow(), created_by_id=user_id, aircraft_id=aircraft_id, completed=False, blocked=blocked) new_item.id = get_timebased_uuid() aircraft = AircraftManager.get(aircraft_id) if aircraft.health != AircraftHealth.BLOCKING: aircraft.health = AircraftHealth.BLOCKING if blocked else AircraftHealth.NON_BLOCKING db_session.add(new_item) db_session.commit() return new_item
def completed(id): maintenance = MaintenanceManager.get(id) maintenance.completed = True db_session.commit() return maintenance.aircraft_id, MaintenanceManager.aircraft_health( maintenance.aircraft_id)
def set_health(id, health): aircraft = AircraftManager.get(id) aircraft.health = health db_session.commit() return AircraftManager.get(id)