Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def save_lithrometric_probe_data(request, agency_id):
- if request.method == "POST":
- try:
- json_data = json.loads(request.body)
- sn = json_data['sn']
- value = int(json_data['value'])
- device_id = int(json_data['device_id'])
- device = Device.objects.get(id=device_id)
- probe, created = LithrometricProbe.objects.update_or_create(serial_number=sn, defaults={
- "probe_value": value,
- "device": device
- })
- probe.volume_value = get_volume_for_probe_value(probe, value)
- probe.save()
- LithrometricValue.objects.create(
- lithrometric_probe=probe,
- probe_value=value,
- volume_value=probe.volume_value,
- )
- return JSONResponse({"success": True})
- except ValueError as e:
- return JSONResponse({"success": False, "err_msg": str(e)}, status=400)
- except KeyError as e:
- return JSONResponse({"success": False, "err_msg": "Missing value: " + str(e)}, status=400)
- else:
- return HttpResponse("ERROR: Invalid request method " + request.method)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement