예제 #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 registerDriver(request):
    if not request.user.is_superuser:
        return HttpResponseRedirect('/home')
    status = 'normal'
    if request.method == 'POST':
        form = AddDriverForm(request.POST)
        if form.is_valid():
            driverId = dbaccess.getMaxDriverId()+1
            params = [
                driverId,
                request.POST['firstName'],
                request.POST['lastName'],
                request.POST['driverContactNo'],
                request.POST['drivingClass'],
                request.session['coyId']
            ]
            dbaccess.insertDriver(params)
            if request.get_full_path().__contains__('id'):
                return HttpResponseRedirect('/admin/addDriver/id='+str(request.session['coyId']))
            else:
                return HttpResponseRedirect('/admin/addDriver')
    else:
        form = AddDriverForm()
        if request.get_full_path().__contains__('id'):
            request.session['coyId'] = request.get_full_path().split('=')[1]
            status = 'redirect'
        else:
            if 'coyId' not in request.session:
                return HttpResponseRedirect('/home')
        print(status)
    if 'coyId' in request.session:
        coyId = request.session['coyId']
    else:
        coyId = None
    return render_to_response('admin/addDriver.html', {
        'form': form,
        'status': status,
        'coyId': coyId
    }, context_instance=RequestContext(request))