def create_test_stations():
    # one in Tel Aviv
    station_name = STATION_NAMES[0]

    station = Station()
    station.name = station_name
    station.user = User.objects.get(username=station_name)
    station.number_of_taxis = 5
    station.country = Country.objects.filter(code="IL").get()
    station.city = City.objects.get(name="תל אביב יפו")
    station.address = 'דיזנגוף 99 תל אביב יפו'
    station.lat = 32.07938
    station.lon = 34.773896
    station.save()

    phone = Phone(local_phone=u'1234567', station=station)
    phone.save()

    # and one in Jerusalem
    station_name = STATION_NAMES[1]

    station = Station()
    station.name = station_name
    station.user = User.objects.get(username=station_name)
    station.number_of_taxis = 5
    station.country = Country.objects.filter(code="IL").get()
    station.city = City.objects.get(name="ירושלים")
    station.address = 'בן יהודה 35 ירושלים'
    station.lat = 31.780725
    station.lon = 35.214161
    station.save()

    phone = Phone(local_phone=u'1234567', station=station)
    phone.save()
Esempio n. 2
0
def create_another_TLV_station(num_of_ws=1):
    # create another station in TLV
    tel_aviv = City.objects.get(name=u'תל אביב יפו')
    station_name = 'tel_aviv_%d' % (
        Station.objects.filter(city=tel_aviv).count() + 1)
    ws_names = []
    for i in range(num_of_ws):
        ws_names.append("%s_%s%d" % (station_name, "ws", i + 1))

    station = None
    for user_name in [station_name] + ws_names:
        user = User(username=user_name)
        user.set_password(user_name)
        user.save()

        if user_name == station_name:
            station = Station(name=station_name,
                              user=user,
                              number_of_taxis=5,
                              country=Country.objects.filter(code="IL").get(),
                              city=City.objects.get(name="תל אביב יפו"),
                              address='גאולה 12',
                              lat=32.071838,
                              lon=34.766906)
            station.save()
        else:
            ws = WorkStation(user=user,
                             station=station,
                             was_installed=True,
                             accept_orders=True)
            ws.save()

    return station
Esempio n. 3
0
def create_selenium_station(user):
    selenium_station = Station(name="selenium_station",
                               user=user,
                               number_of_taxis=5,
                               country=Country.objects.filter(code="IL").get(),
                               city=City.objects.get(name=SELENIUM_CITY_NAME),
                               address=SELENIUM_ADDRESS,
                               lat=32.105137,
                               lon=35.198071,
                               license_number="1234",
                               postal_code='1234',
                               website_url="http://selenium.waybetter.com")
    selenium_station.save()

    phone = Phone(local_phone=SELENIUM_PHONE, station=selenium_station)
    phone.save()

    #    selenium_station.build_workstations()

    return selenium_station
Esempio n. 4
0
    def register(self, request, **kwargs):
        """
        Given a username, email address and password, register a new
        user account, which will initially be inactive.

        Along with the new ``User`` object, a new
        ``registration.models.RegistrationProfile`` will be created,
        tied to that ``User``, containing the activation key which
        will be used for this account.

        An email will be sent to the supplied email address; this
        email should contain an activation link. The email will be
        rendered using two templates. See the documentation for
        ``RegistrationProfile.send_activation_email()`` for
        information about these templates and the contexts provided to
        them.

        After the ``User`` and ``RegistrationProfile`` are created and
        the activation email is sent, the signal
        ``registration.signals.user_registered`` will be sent, with
        the new ``User`` as the keyword argument ``user`` and the
        class of this backend as the sender.

        """
        username, email, password, first_name, last_name = kwargs[
            'username'], kwargs['email'], kwargs['password1'], kwargs[
                'first_name'], kwargs['last_name']
        if Site._meta.installed:
            site = Site.objects.get_current()
        else:
            site = RequestSite(request)

        try:
            new_user = RegistrationProfile.objects.create_inactive_user(
                username, email, password, site, first_name, last_name)
        except:
            new_user = User.objects.get(username=username)
            logging.error("user creation failed, probably email related")

        new_station = Station()
        new_station.user = new_user
        new_station.address = kwargs['address']
        new_station.city = kwargs['city']
        new_station.country = kwargs['country']
        new_station.name = kwargs['name']
        new_station.license_number = kwargs['license_number']
        new_station.website_url = kwargs['website_url']
        new_station.number_of_taxis = kwargs['number_of_taxis']
        new_station.description = kwargs['description']
        new_station.logo = kwargs['logo']
        new_station.language = kwargs['language']
        new_station.save()

        phone = Phone()
        phone.station = new_station
        phone.local_phone = kwargs['local_phone']
        phone.save()

        signals.user_registered.send(sender=self.__class__,
                                     user=new_user,
                                     request=request)
        return new_user
Esempio n. 5
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)