revamped update logic -- updated dummy JSON to mirror a full report

This commit is contained in:
Rupika 2019-02-13 17:41:28 -08:00
parent b2088291df
commit 11b1de72b3
2 changed files with 21 additions and 15 deletions

View file

@ -155,22 +155,28 @@ def report_detail(request, report_pk):
# update a section with new data # update a section with new data
@api_view(['PUT']) @api_view(['PUT'])
def section(request, report_pk, section_pk): def section(request, report_pk, section_pk):
for v in request.data["fields"]: # first enter sections
update_field = Field.objects.get(id=v["id"]) for s in request.data["sections"]:
# check for match
if s["id"] == section_pk:
# begin updating fields
for v in s["fields"]:
update_field = Field.objects.get(id=v["id"])
if v["type"] == "boolean": if v["type"] == "boolean":
update_field.data_bool = v["value"] update_field.data_bool = v["value"]
if v["type"] == "decimal": if v["type"] == "decimal":
update_field.data_decimal = v["value"] update_field.data_decimal = v["value"]
if v["type"] == "date": if v["type"] == "date":
update_field.data_date = v["value"] update_field.data_date = v["value"]
if v["type"] == "file": if v["type"] == "file":
update_field.data_file = v["value"] update_field.data_file = v["value"]
if v["type"] == "string": if v["type"] == "string":
update_field.data_string = v["value"] update_field.data_string = v["value"]
if v["type"] == "integer": if v["type"] == "integer":
update_field.data_integer = v["value"] update_field.data_integer = v["value"]
update_field.save() update_field.save()
return JsonResponse({"message": "Updated report {0}, section {1}.".format(report_pk, section_pk)}) return JsonResponse({"message": "Updated report {0}, section {1}.".format(report_pk, section_pk)})

Binary file not shown.