예제 #1
0
def editCompany(request):
    print 'asd'
    if not request.user.is_superuser:
        return HttpResponseRedirect('/home')
    coyRow = dbaccess.getCompanyById(request.get_full_path().split('=')[1])
    if request.method == 'POST':
        form = EditCompanyForm(request.POST)
        if form.is_valid():
            params = [
                request.POST['coyName'],
                coyRow[2],
                request.POST['faxNo'],
                request.POST['coyContactNo'],
                request.POST['zipcode'],
                request.POST['streetName'],
                coyRow[0]
            ]
            dbaccess.updateCompany(params)
            return HttpResponseRedirect('/admin/viewCompany')
    else:
        form = EditCompanyForm(initial={
            'coyName': coyRow[1],
            'email': coyRow[2],
            'faxNo': coyRow[3],
            'coyContactNo': coyRow[4],
            'zipcode': coyRow[5],
            'streetName': coyRow[6],
        })
    return render_to_response('admin/editCompany.html', {
        'form': form,
        'email': coyRow[2],
    }, context_instance=RequestContext(request))
예제 #2
0
def viewCompanyProfile(request):
    coyId = request.get_full_path().split('=')[1]
    coy = dbaccess.getCompanyById(coyId)
    coyDetails = SortedDict([
        ('Address', coy[6]),
        ('Postal Code', coy[5]),
        ('Contact Number', coy[4]),
        ('Fax Number', coy[3]),
        ('Email', coy[2]),
        ])

    drivers = dbaccess.getNumDriByClassByCoy(coyId)
    no3 = 0
    no3a = 0
    no4 = 0
    no4a = 0
    no5 = 0

    for driver in drivers:
        if driver[0] == '3':
            no3 = driver[1]
        if driver[0] == '3a':
            no3a = driver[1]
        if driver[0] == '4':
            no4 = driver[1]
        if driver[0] == '4a':
            no4a = driver[1]
        if driver[0] == '5':
            no5 = driver[1]

    driverDetails = SortedDict([
        ('Class 3', no3),
        ('Class 3a', no3a),
        ('Class 4', no4),
        ('Class 4a', no4a),
        ('Class 5', no5),
        ])

    vehicles = dbaccess.getNumVehByCatByCoy(coyId)
    sedanNo = 0
    luxuryNo = 0
    mpvNo = 0
    busNo = 0
    minibusNo = 0
    coachNo = 0
    ton1No = 0
    ton3No = 0
    ton5No = 0

    for vehicle in vehicles:
        if vehicle[0] == 'Car':
            if vehicle[1] == 'sedan':
                sedanNo = vehicle[2]
            if vehicle[1] == 'luxury':
                luxuryNo = vehicle[2]
            if vehicle[1] == 'mpv':
                mpvNo = vehicle[2]
        elif vehicle[0] == 'Bus':
            if vehicle[1] == 'bus':
                busNo = vehicle[2]
            if vehicle[1] == 'mini':
                minibusNo = vehicle[2]
            if vehicle[1] == 'coach':
                coachNo = vehicle[2]
        elif vehicle[0] == 'Lorry':
            if vehicle[1] == ' 1':
                ton1No = vehicle[2]
            if vehicle[1] == ' 3':
                ton3No = vehicle[2]
            if vehicle[1] == ' 5':
                ton5No = vehicle[2]

    carDetails = SortedDict([
        ('Sedan', sedanNo),
        ('Luxury', luxuryNo),
        ('MPV', mpvNo),
        ])

    busDetails = SortedDict([
        ('Bus', busNo),
        ('Minibus', minibusNo),
        ('Coach', coachNo),
        ])

    lorryDetails = SortedDict([
        ('1 Ton', ton1No),
        ('3 Ton', ton3No),
        ('5 Ton', ton5No),
        ])

    return render_to_response('admin/companyProfile.html', {
        'coy': coy,
        'coyDetails': coyDetails,
        'driverDetails': driverDetails,
        'carDetails': carDetails,
        'busDetails': busDetails,
        'lorryDetails': lorryDetails
    }, context_instance=RequestContext(request))