Example #1
0
def change_ride(request, ride_id):
    instance = get_object_or_404(Ride, pk=ride_id)
    form = RideForm(request.POST or None, instance=instance)
    if form.is_valid():
        new_ride = form.save(commit=False)
        new_ride.pay=round(6*round(float(new_ride.calculatedDistance), 1), 1)
        form.save()
        return HttpResponseRedirect('/ridelist/')
    return render(request, 'taximanager/changeRide.html', {'form': form})
Example #2
0
def new_ride(request):
    driver = Driver.objects.all()
    cab = Cab.objects.all()
    status = Status.objects.all()
    default_status = Status.objects.get(name='Accepted')
    if request.method == 'POST':
        form = RideForm(request.POST)   # A form bound to the POST data
        if form.is_valid():     # All validation rules pass
            new_ride = form.save(commit=False)
            new_ride.loginID = request.user
            new_ride.status=default_status
            send_mail('Taxi manager', 'Status is: ' + new_ride.status.name, settings.EMAIL_HOST_USER,
                      [new_ride.email], fail_silently=False)
            new_ride.pay=round(6*round(float(new_ride.calculatedDistance), 1), 1)
            new_ride.save()
            return HttpResponseRedirect('/ridelist/')
    else:
        form = RideForm()
    context = {'driver':driver, 'cab': cab, 'status': status, 'form': form}
    return render(request, 'taximanager/new_ride.html', context)