Example #1
0
def driver_list(request):
    if request.method == "GET":
        drivers = Driver.objects.all()
        serializer = DriverSerializer(drivers, many=True)
        return JSONResponse(serializer.data)

    elif request.method == "POST":
        data = JSONParser().parse(request)
        serializer = DriverSerializer(data=data)
        if serializer.is_valid():
            serializer.save()
            return JSONResponse(serializer.data, status=201)
        return JSONResponse(serializer.errors, status=400)
Example #2
0
def driver_get_nearby(request):
    get = request.GET
    radius = float(get.__getitem__('radius'))
    latitude = float(get.__getitem__('latitude'))
    longitude = float(get.__getitem__('longitude'))
    longmax = longitude + radius
    longmin = longitude - radius
    latmax = latitude + radius
    latmin = latitude - radius
    drivers = Driver.objects.all().filter(pos_lat__gte=latmin, pos_lat__lte=latmax,pos_long__gte=longmin, pos_long__lte=longmax)
    serializer = DriverSerializer(drivers, many=True)
    return JSONResponse(serializer.data, status = 201)
Example #3
0
def driver_list(request):
    if request.method == 'GET':
        drivers = Driver.objects.all()
        serializer = DriverSerializer(drivers, many=True)
        return JSONResponse(serializer.data)
        
    elif request.method == 'POST':
        data = JSONParser().parse(request)
        serializer = DriverSerializer(data=data)
        if serializer.is_valid():
            serializer.save()
            return JSONResponse(serializer.data, status=201)
        return JSONResponse(serializer.errors, status=400)
Example #4
0
def driver_login(request):
    get = request.GET
    driverid = get.__getitem__('id')
    lat = get.__getitem__('latitude')
    lon = get.__getitem__('longitude')
    driver = Driver.objects.filter(driver_id = driverid)
    if driver.count() == 1:
        drivers = Driver.objects.get(driver_id = driverid)
        drivers.pos_lat = lat
        drivers.pos_long = lon
        drivers.save()
        serializer = DriverSerializer(driver[0])
        return JSONResponse(serializer.data, status = 201)        
    else:
        return HttpResponse('id not valid',status = 401)
Example #5
0
def driver_register(request):
    serializer = DriverSerializer(data=request.GET)
    if serializer.is_valid():
        serializer.save()
        return JSONResponse(serializer.data, status=201)
    return JSONResponse(serializer.errors, status=400)
Example #6
0
def driver_register(request):
    serializer = DriverSerializer(data = request.GET)
    if serializer.is_valid():
        serializer.save()
        return JSONResponse(serializer.data, status=201)
    return JSONResponse(serializer.errors, status=400)