示例#1
0
def sensor_resource(request, sensor_id):
    if request.method == "GET":
        username = request.user.username
        sensors_list = get_sensors(username)

        if sensor_id not in sensors_list:
            return HttpResponseNotFound("Sensor '%s' does not exist" % sensor_id)

        sensor = {
            'id': sensor_id,
            'uri': '/api/%s/sensors/%s' % (API_VERSION, sensor_id)
        }

        return HttpResponse(json.dumps(sensor), mimetype='application/javascript')
示例#2
0
def sensors(request):
    if request.method == "GET":
        username = request.user.username
        sensors_list = get_sensors(username)
        sensors = []

        for sensor in sensors_list:
            s = {
                'id': sensor,
                'uri': '/api/%s/sensors/%s' % (API_VERSION, sensor)
            }
            sensors.append(s)

        return HttpResponse(json.dumps(sensors), mimetype='application/javascript')