Esempio n. 1
0
def post_request(request, query_params, **kwargs):
    # gets the data from the POST
    s = request.raw_post_data
    ds = dejsonify(s)
    username = ds["username"]
    password = ds["password"]
    # check the users information to make sure they have a valid account
    user = authenticate(username=username, password=password)

    if user is not None:
        d = ds["Serial"]
        a = ds["appname"]
        # check if the app is in the database and add it if it is not
        try:
            device = Device.objects.get(serial=d)
        except Device.DoesNotExist:
            device = Device(
                serial=ds["Serial"],
                screenWidth=ds["screen width"],
                screenHeight=ds["screen height"],
                version=ds["Version"],
                user=user,
            )
            device.save()
        try:
            app = App.objects.get(appname=a)
        except App.DoesNotExist:
            app = App(appname=ds["appname"], user=user)
            app.save()
            # add a session with this information
        session = Session(user=user, device=device, app=app)
        session.save()
        arraySize = len(ds["Motion Events"])
        # get the motion event array from the POST
        motion = ds["Motion Events"]
        # for each index of the array add it as a motion event in the table
        for i in range(0, arraySize):
            MotionEvent(
                action=motion[i]["action"],
                deviceId=motion[i]["deviceId"],
                downTime=motion[i]["downTime"],
                edgeFlags=motion[i]["edgeFlags"],
                eventTime=motion[i]["eventTime"],
                metaState=motion[i]["metaState"],
                pressure=motion[i]["pressure"],
                size=motion[i]["size"],
                x=motion[i]["x"],
                xPrecision=motion[i]["xPrecision"],
                y=motion[i]["y"],
                yPrecision=motion[i]["yPrecision"],
                sessionId=session,
            ).save()
        return HttpResponse("added data to DB")
    else:
        return HttpResponse("invalid request")
Esempio n. 2
0
def post_request(request, query_params, **kwargs):
    #gets the data from the POST
    s = request.raw_post_data
    ds = dejsonify(s)
    username = ds['username']
    password = ds['password']
    # check the users information to make sure they have a valid account
    user = authenticate(username=username, password=password)

    if user is not None:
        d = ds['Serial']
        a = ds['appname']
        # check if the app is in the database and add it if it is not
        try:
            device = Device.objects.get(serial=d)
        except Device.DoesNotExist:
            device = Device(serial=ds['Serial'],
                            screenWidth=ds['screen width'],
                            screenHeight=ds['screen height'],
                            version=ds['Version'],
                            user=user)
            device.save()
        try:
            app = App.objects.get(appname=a)
        except App.DoesNotExist:
            app = App(appname=ds['appname'], user=user)
            app.save()
    # add a session with this information
        session = Session(user=user, device=device, app=app)
        session.save()
        arraySize = len(ds['Motion Events'])
        # get the motion event array from the POST
        motion = ds['Motion Events']
        # for each index of the array add it as a motion event in the table
        for i in range(0, arraySize):
            MotionEvent(action=motion[i]['action'],
                        deviceId=motion[i]['deviceId'],
                        downTime=motion[i]['downTime'],
                        edgeFlags=motion[i]['edgeFlags'],
                        eventTime=motion[i]['eventTime'],
                        metaState=motion[i]['metaState'],
                        pressure=motion[i]['pressure'],
                        size=motion[i]['size'],
                        x=motion[i]['x'],
                        xPrecision=motion[i]['xPrecision'],
                        y=motion[i]['y'],
                        yPrecision=motion[i]['yPrecision'],
                        sessionId=session).save()
        return HttpResponse('added data to DB')
    else:
        return HttpResponse('invalid request')
Esempio n. 3
0
def manageDevices(request):
    state= "Enter your device information."    
    c = {}
    c.update(csrf(request))
    if request.POST:
        # get the device info entered
        serial = request.POST.get('serial')
        version = request.POST.get('version')
        screenWidth = request.POST.get('screenWidth')
        screenHeight = request.POST.get('screenHeight')
        # add a deivce with the entered info to the database
        device = Device(serial=serial,version=version,screenWidth=screenWidth,screenHeight=screenHeight,user=request.user)
        device.save()
        #displays so the user knows the device successfully added
        state = "Device was successfully added"
        return render_to_response('device.html',{"state":state},context_instance=RequestContext(request))
    else:                
        return render_to_response('device.html',{"state":state},context_instance=RequestContext(request))