示例#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 manageApps(request):
    state="Enter the App name"
    c = {}
    c.update(csrf(request))
    if request.POST:
        # get the app name entered by the user
        appname = request.POST.get('appname')
        # add the app and the associated user to the database
        app = App(appname=appname, user=request.user)
        app.save()
        # displays so that the user knows the were successful in adding the app
        state = "App was successfully added"
        return render_to_response('app.html',{"state":state},context_instance=RequestContext(request))
    else:                
        return render_to_response('app.html',{"state":state},context_instance=RequestContext(request))