Пример #1
0
    def get_driven_cars(self, database_connection):
        query = """SELECT state, plate_num, building_id
                   FROM vehicles NATURAL JOIN drives NATURAL JOIN entrants
                   WHERE entrant_id = :eid"""
        cursor = database_connection.execute(text(query), eid=self.entrant_id)

        cars = []
        for state, plate_num, building_id in cursor:
            car = vehicles.find_by_license_plate(
                    database_connection, state, plate_num, building_id)
            if car:
                cars.append(car)
        return cars
Пример #2
0
    def add_as_driver(state, plate_num, building_id, entrant_id,
            database_connection):
        car = vehicles.find_by_license_plate(database_connection,
                                             state, plate_num, building_id)
        if not car:
            return False

        drivers = car.get_drivers(database_connection)
        for driver in drivers:
            if driver.entrant_id == entrant_id:
                return True

        query = """INSERT INTO drives
                        (entrant_id, building_id, plate_num, state)
                   VALUES (:eid, :bid, :plate_num, :state)"""
        database_connection.execute(text(query),
                                    eid=entrant_id,
                                    bid=building_id,
                                    plate_num=plate_num,
                                    state=state)
        return True