예제 #1
0
def editDriver(request):
    if not request.user.is_superuser:
        return HttpResponseRedirect('/home')
    driverRow = dbaccess.getDriverByDid(request.get_full_path().split('=')[1])
    if request.method == 'POST':
        form = AddDriverForm(request.POST)
        if form.is_valid():
            params = [
                request.POST['firstName'],
                request.POST['lastName'],
                request.POST['driverContactNo'],
                request.POST['drivingClass'],
                driverRow[0]
            ]
            dbaccess.updateDriver(params)
            return HttpResponseRedirect('/admin/viewDriver/id=' + str(driverRow[5]))
    else:
        form = AddDriverForm(initial={
            'firstName': driverRow[1],
            'lastName': driverRow[2],
            'driverContactNo': driverRow[3],
            'drivingClass': driverRow[4],
        })
    return render_to_response('admin/editDriver.html', {
        'form': form,
    }, context_instance=RequestContext(request))
예제 #2
0
def deleteDriver(request):
    if not request.user.is_superuser:
        return HttpResponseRedirect('/home')
    coyId = dbaccess.getDriverByDid(request.get_full_path().split('=')[1])[5]
    if dbaccess.checkIfDriverHaveTrips(request.get_full_path().split('=')[1]) == False:
        return render_to_response('admin/deleteDriverError.html', {
            'coyId': coyId
        }, context_instance=RequestContext(request))
    else:
        dbaccess.deleteDriver(request.get_full_path().split('=')[1])
        return HttpResponseRedirect('/admin/viewDriver/id=' + str(coyId))