Пример #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")
Пример #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')
Пример #3
0
def __create__(request, query_params, **kwargs):	
	s = request.raw_post_data
	ds = dejsonify(s)
	username = ds['username']
	password = ds['password']
	user = authenticate(username=username, password=password)
	
	if user is not None:	
	    session = Session(user=user)
	    session.save()
	    arraySize = len(ds['Motion Events'])	
	    motion = ds['Motion Events']
	    t = 0
	    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(t)
	else:
	    return HttpResponse(t)
Пример #4
0
def __create__(request, query_params, **kwargs):	
	s = request.raw_post_data
	ds = dejsonify(s)
	username = ds['username']
	password = ds['password']
	user = authenticate(username=username, password=password)
	
	if user is not None:	
	    session = Session(user=user)
	    session.save()
	    arraySize = len(ds['Motion Events'])	
	    motion = ds['Motion Events']
	    t = 0
	    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(t)
	else:
	    return HttpResponse(t)