def store_reading(request, reading_id): ''' Stores a sensor or calculated reading in the sensor reading database. 'reading_id' is the ID of the reading to store. Other information about the reading is in the GET parameter or POST data of the request. ''' try: # determine whether request was a GET or POST and extract data req_data = request.GET.dict( ) if request.method == 'GET' else request.POST.dict() # Test for a valid key for storing readings. Key should be unique for each # installation. storeKey = req_data['storeKey'] del req_data[ 'storeKey'] # for safety, get the key out of the dictionary if store_key_is_valid(storeKey): msg = storereads.store(reading_id, req_data) return HttpResponse(msg) else: _logger.warning('Invalid Storage Key in Reading Post: %s', storeKey) return HttpResponse('Invalid Key') except: _logger.exception('Error Storing Reading for ID=%s: %s' % (reading_id, req_data)) return HttpResponse(sys.exc_info()[1])
def store_reading_old(request, store_key): ''' Stores a reading that uses an older URL pattern. ''' try: if store_key == settings.BMSAPP_STORE_KEY_OLD: # determine whether request was a GET or POST and extract data req_data = request.GET.dict() if request.method == 'GET' else request.POST.dict() # pull the reading id out of the request parameters reading_id = req_data['id'] storereads.store(reading_id, req_data) return HttpResponse('OK') else: return HttpResponse('Invalid Key') except: _logger.exception('Error Storing Reading for: %s' % req_data) return HttpResponse('Error Storing Reading')
def store_reading_old(request, store_key): ''' Stores a reading that uses an older URL pattern. ''' try: if store_key == settings.BMSAPP_STORE_KEY_OLD: # determine whether request was a GET or POST and extract data req_data = request.GET.dict( ) if request.method == 'GET' else request.POST.dict() # pull the reading id out of the request parameters reading_id = req_data['id'] storereads.store(reading_id, req_data) return HttpResponse('OK') else: return HttpResponse('Invalid Key') except: _logger.exception('Error Storing Reading for: %s' % req_data) return HttpResponse('Error Storing Reading')
def store_reading(request, reading_id): ''' Stores a sensor or calculated reading in the sensor reading database. 'reading_id' is the ID of the reading to store. Other information about the reading is in the GET parameter or POST data of the request. ''' try: # determine whether request was a GET or POST and extract data req_data = request.GET.dict() if request.method == 'GET' else request.POST.dict() # Test for a valid key for storing readings. Key should be unique for each # installation. storeKey = req_data['storeKey'] del req_data['storeKey'] # for safety, get the key out of the dictionary if store_key_is_valid(storeKey): msg = storereads.store(reading_id, req_data) return HttpResponse(msg) else: _logger.warning('Invalid Storage Key in Reading Post: %s', storeKey) return HttpResponse('Invalid Key') except: _logger.exception('Error Storing Reading for ID=%s: %s' % (reading_id, req_data)) return HttpResponse(sys.exc_info()[1])