From 11b1de72b37ac76081f6c4a767071bd99e95b3b6 Mon Sep 17 00:00:00 2001 From: Rupika Date: Wed, 13 Feb 2019 17:41:28 -0800 Subject: [PATCH] revamped update logic -- updated dummy JSON to mirror a full report --- back/backend/views.py | 36 +++++++++++++++++++++--------------- back/db.sqlite3 | Bin 105472 -> 105472 bytes 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/back/backend/views.py b/back/backend/views.py index 8cf55ae..dc6b826 100644 --- a/back/backend/views.py +++ b/back/backend/views.py @@ -155,22 +155,28 @@ def report_detail(request, report_pk): # update a section with new data @api_view(['PUT']) def section(request, report_pk, section_pk): - for v in request.data["fields"]: - update_field = Field.objects.get(id=v["id"]) + # first enter sections + 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": - update_field.data_bool = v["value"] - if v["type"] == "decimal": - update_field.data_decimal = v["value"] - if v["type"] == "date": - update_field.data_date = v["value"] - if v["type"] == "file": - update_field.data_file = v["value"] - if v["type"] == "string": - update_field.data_string = v["value"] - if v["type"] == "integer": - update_field.data_integer = v["value"] + if v["type"] == "boolean": + update_field.data_bool = v["value"] + if v["type"] == "decimal": + update_field.data_decimal = v["value"] + if v["type"] == "date": + update_field.data_date = v["value"] + if v["type"] == "file": + update_field.data_file = v["value"] + if v["type"] == "string": + update_field.data_string = v["value"] + if v["type"] == "integer": + 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)}) + diff --git a/back/db.sqlite3 b/back/db.sqlite3 index 9f8e18213a65a0090e546a253ad442f235486114..648001700c0d381b0ad43a87bef2d24c7ed8b0ce 100644 GIT binary patch delta 233 zcmZqJ!Pc;YZGtr8xrs8)jOQ8?wk9wxtgdJ3WZ-AeW@O&VT*2(b%*LS2kifK+$)8D> z@fzb2#$rYthKCHZ7(l?V(S(mdlu??4gI$rAmxEE%EwLz-DJ3;IGdD5Efm3cr;Oka- zBLhQAT>~RsLnEIwkhFQDDIbF>ND~846BDCsNKs;5ab}4^d17V>b7tQ3`Wi-lCUt@B z6KfcMFtPxx(V5;`$Ed;O*J#Ga;0x5qIsIWIqx$q+b&Lw^mW{@I44RzN??*98aHJ%b Xqynuoo32~WXvzX&ZBMIboFxMQ$!a?N delta 197 zcmZqJ!Pc;YZGtr8$%!(~j3*ltwk9wxtX5@UVBlwnXJFpST*2(b%*J$!A)cv|$)8D> z@fzb2#$rYthKCHZCL6L?@>?{T@-e6~N^@{9DDv_$PtUJmRA6R|pRj#m4dV|+7QaR_ zzUjSnj2hDyL^HBZe^$q+V653_!p9&A(!v4M!oeu&mROX^l#-g9nVXnnWMF8iYha{n tXylUy6t-+M=3~(0oPIxwQGz2Su_V>d($aFeZat$Z3y8Hnt)6j~3;^%