def handle_failed_ride(sender, signal_type, ride, status, **kwargs): from ordering.enums import RideStatus from ordering.models import FAILED from fleet.fleet_manager import cancel_ride from sharing.station_controller import send_ride_in_risk_notification from notification.api import notify_passenger if ride.status == RideStatus.FAILED: logging.info("handling FAILED ride: %s" % ride.id) current_lang = translation.get_language() # cancel ride cancel_ride(ride) # notify us send_ride_in_risk_notification(u"Ride failed because it was not accepted in time", ride.id) # cancel orders and notify passengers for order in ride.orders.all(): order.change_status(new_status=FAILED) translation.activate(order.language_code) notify_passenger(order.passenger, _("We're sorry but we couldn't find a taxi for you this time. (Order: %s)") % order.id) translation.activate(current_lang)
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 manual_dispatch(request, work_station, ride_id): ride = SharedRide.by_id(ride_id) taxi_number = request.POST.get("taxi_number") pickup_estimate = request.POST.get("pickup_estimate") if taxi_number and pickup_estimate and ride and ride.station == work_station.station: ride.taxi_number = taxi_number ride.pickup_estimate = int(pickup_estimate) fleet_manager.cancel_ride(ride) fleet_manager.create_ride(ride) ride.change_status(old_status=RideStatus.VIEWED, new_status=RideStatus.ACCEPTED) return HttpResponse("OK") return HttpResponseForbidden()
def resend_to_fleet_manager(request, ride_id): resend_result = False ride = SharedRide.by_id(ride_id) cancel_result = fleet_manager.cancel_ride(ride) if cancel_result: resend_result = fleet_manager.create_ride(ride) return JSONResponse({'result': resend_result})
def reassign_ride(request, work_station, ride_id): ride = SharedRide.by_id(ride_id) if ride and ride.station == work_station.station: ride.update(taxi_number=None) if fleet_manager.cancel_ride(ride) and fleet_manager.create_ride(ride): return HttpResponse("OK") else: logging.error("could not reassign ride: %s" % ride_id) return HttpResponseForbidden()
def cancel_ride(ride_id): ride = FakeSharedRide([]) ride.id = ride_id ride.dn_fleet_manager_id = isr_fm.id return fleet_manager.cancel_ride(ride)