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
def station_snapshot(request, station_id): lib_ng = True memcache.set(str(station_id), "", namespace=WORKSTATION_SNAPSHOTS_NS) station = Station.by_id(station_id) return render_to_response("station_snapshot.html", locals(), context_instance=RequestContext(request))
def station_snapshot_update(request, station_id): from ordering.station_connection_manager import _do_push station = Station.by_id(station_id) # send push ws = station.work_stations.filter(accept_shared_rides=True)[0] if ws: _do_push(ws, {"action": "get_snapshot"}) return HttpResponse("OK")
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
def manual_assign_ride(request): from sharing.sharing_dispatcher import assign_ride ride_id = request.POST.get("ride_id") station_id = request.POST.get("station_id") ride = SharedRide.by_id(ride_id) station = Station.by_id(station_id) if station and ride.station != station: fleet_manager.cancel_ride(ride) assign_ride(ride, station) return JSONResponse({'ride': ride.serialize_for_eagle_eye()})
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
def calc_ny_sharing(offset=0, count=0, value=0): batch_size = 500 logging.info("querying shared rides %s->%s" % (offset, offset + batch_size)) s = Station.by_id(1529226) shared_rides = SharedRide.objects.filter(station=s)[offset: offset + batch_size] for sr in shared_rides: count += 1 value += sr.cost if shared_rides: deferred.defer(calc_ny_sharing, offset=offset + batch_size + 1, count=count, value=value) else: logging.info("all done, sending report") send_mail_as_noreply("*****@*****.**", "Shared rides data for NY", msg="count=%d, value=%f" % (count, value))
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
def calc_ny_sharing(offset=0, count=0, value=0): batch_size = 500 logging.info("querying shared rides %s->%s" % (offset, offset + batch_size)) s = Station.by_id(1529226) shared_rides = SharedRide.objects.filter(station=s)[offset:offset + batch_size] for sr in shared_rides: count += 1 value += sr.cost if shared_rides: deferred.defer(calc_ny_sharing, offset=offset + batch_size + 1, count=count, value=value) else: logging.info("all done, sending report") send_mail_as_noreply("*****@*****.**", "Shared rides data for NY", msg="count=%d, value=%f" % (count, value))
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()
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
logging.info("station_unique_id submitted: %s" % station_unique_id) stations = Station.objects.filter(unique_id=station_unique_id) if stations: order.originating_station = stations[0] order.confining_station = stations[0] else: return error_response( _("Could not send order to specified station")) order.save() order_created_signal.send(sender="order_created_signal", obj=order) if passenger.phone != settings.APPLE_TESTER_PHONE_NUMBER: order_manager.book_order_async(order) else: # assign order to test station so the user will see it in his history order.station = Station.by_id(1713061) order.pickup_time = 5 order.save() order.change_status(old_status=PENDING, new_status=ACCEPTED) log_event(EventType.ORDER_BOOKED, order=order) book_order_message = _( 'An SMS with ride details will arrive shortly...') if order.originating_station_id: book_order_message = _( "%s is looking for a free taxi. An SMS with ride details will arrive shortly..." ) % order.originating_station.name book_order_result = { "status":
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
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)
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)
if station_unique_id: logging.info("station_unique_id submitted: %s" % station_unique_id) stations = Station.objects.filter(unique_id=station_unique_id) if stations: order.originating_station = stations[0] order.confining_station = stations[0] else: return error_response(_("Could not send order to specified station")) order.save() order_created_signal.send(sender="order_created_signal", obj=order) if passenger.phone != settings.APPLE_TESTER_PHONE_NUMBER: order_manager.book_order_async(order) else: # assign order to test station so the user will see it in his history order.station = Station.by_id(1713061) order.pickup_time = 5 order.save() order.change_status(old_status=PENDING, new_status=ACCEPTED) log_event(EventType.ORDER_BOOKED, order=order) book_order_message = _("An SMS with ride details will arrive shortly...") if order.originating_station_id: book_order_message = ( _("%s is looking for a free taxi. An SMS with ride details will arrive shortly...") % order.originating_station.name ) book_order_result = { "status": "booked",