Пример #1
0
def create_ride(address, comments, passenger_phone, first_name, last_name, start_time, finish_time, station_id, as_raw_output):
    from common.tz_support import set_default_tz_time
    from geo.coder import geocode

    if not address:
        return "Please choose a valid street address: street, house number and city"

    lat, lon, city, street, house_number = None, None, None, None, None
    results = geocode(address, lang_code="he")
    if results:
        result = results[0]
        if "street_address" in result["types"]:
            lat = result["geometry"]["location"]["lat"]
            lon = result["geometry"]["location"]["lng"]

            for component in result["address_components"]:
                if "street_number" in component["types"]:
                    house_number = component["short_name"]
                if "route" in component["types"]:
                    street = component["short_name"]
                if "locality" in component["types"]:
                    city_name = component["short_name"]
                    city = City.objects.get(name=city_name)

    if not all([lat, lon, city, street, house_number]):
        return "Please choose a valid street address: street, house number and city"

    user = User()
    user.first_name = first_name
    user.last_name = last_name

    passenger = Passenger()
    passenger.user = user
    passenger.phone = passenger_phone
    passenger.id = random.randrange(1, 999999)

    order = Order()
    order.id = random.randrange(1, 999999)
    order.from_raw = address
    order.from_city = city
    order.from_street_address = street
    order.from_house_number = house_number
    order.from_lat = lat
    order.from_lon = lon
    order.comments = comments
    order.depart_time = set_default_tz_time(datetime.datetime.strptime(start_time, "%Y-%m-%dT%H:%M:%S")) if start_time else None
    order.arrive_time = set_default_tz_time(datetime.datetime.strptime(finish_time, "%Y-%m-%dT%H:%M:%S")) if finish_time else None
    order.passenger = passenger

    station = Station()
    station.fleet_manager = isr_fm
    station.fleet_station_id = station_id or 8 # waybetter station operator id

    ride = FakeSharedRide([order])
    ride.id = random.randrange(1, 999999)
    ride.station = station
    ride.dn_fleet_manager_id = isr_fm.id
    ride.status = ASSIGNED

    DEV_WB_ONGOING_RIDES.append(ride)

    if as_raw_output:
        ex_order = ISR._create_external_order(order, station.fleet_station_id)
        reply = ISR._get_client().service.Insert_External_Order(ISR._get_login_token(), ex_order)
        return reply

    return "%s ride id=%s" % (fleet_manager.create_ride(ride), ride.id)
Пример #2
0
def create_ride(address, comments, passenger_phone, first_name, last_name,
                start_time, finish_time, station_id, as_raw_output):
    from common.tz_support import set_default_tz_time
    from geo.coder import geocode

    if not address:
        return "Please choose a valid street address: street, house number and city"

    lat, lon, city, street, house_number = None, None, None, None, None
    results = geocode(address, lang_code="he")
    if results:
        result = results[0]
        if "street_address" in result["types"]:
            lat = result["geometry"]["location"]["lat"]
            lon = result["geometry"]["location"]["lng"]

            for component in result["address_components"]:
                if "street_number" in component["types"]:
                    house_number = component["short_name"]
                if "route" in component["types"]:
                    street = component["short_name"]
                if "locality" in component["types"]:
                    city_name = component["short_name"]
                    city = City.objects.get(name=city_name)

    if not all([lat, lon, city, street, house_number]):
        return "Please choose a valid street address: street, house number and city"

    user = User()
    user.first_name = first_name
    user.last_name = last_name

    passenger = Passenger()
    passenger.user = user
    passenger.phone = passenger_phone
    passenger.id = random.randrange(1, 999999)

    order = Order()
    order.id = random.randrange(1, 999999)
    order.from_raw = address
    order.from_city = city
    order.from_street_address = street
    order.from_house_number = house_number
    order.from_lat = lat
    order.from_lon = lon
    order.comments = comments
    order.depart_time = set_default_tz_time(
        datetime.datetime.strptime(
            start_time, "%Y-%m-%dT%H:%M:%S")) if start_time else None
    order.arrive_time = set_default_tz_time(
        datetime.datetime.strptime(
            finish_time, "%Y-%m-%dT%H:%M:%S")) if finish_time else None
    order.passenger = passenger

    station = Station()
    station.fleet_manager = isr_fm
    station.fleet_station_id = station_id or 8  # waybetter station operator id

    ride = FakeSharedRide([order])
    ride.id = random.randrange(1, 999999)
    ride.station = station
    ride.dn_fleet_manager_id = isr_fm.id
    ride.status = ASSIGNED

    DEV_WB_ONGOING_RIDES.append(ride)

    if as_raw_output:
        ex_order = ISR._create_external_order(order, station.fleet_station_id)
        reply = ISR._get_client().service.Insert_External_Order(
            ISR._get_login_token(), ex_order)
        return reply

    return "%s ride id=%s" % (fleet_manager.create_ride(ride), ride.id)