From 8d630bd3511da86bf0ef688119b594b0b3267b9e Mon Sep 17 00:00:00 2001 From: Rupika Date: Wed, 13 Feb 2019 16:24:17 -0800 Subject: [PATCH] hardcoded dummy json input and updated section --- back/backend/views.py | 74 +++++++++++++++++++++++++++++++++++------- back/db.sqlite3 | Bin 105472 -> 105472 bytes 2 files changed, 63 insertions(+), 11 deletions(-) diff --git a/back/backend/views.py b/back/backend/views.py index fa17a1b..f180169 100644 --- a/back/backend/views.py +++ b/back/backend/views.py @@ -3,6 +3,7 @@ from django.http import JsonResponse from .models import * from .policy import pol import os +# import json # function that prints all the reports @@ -57,7 +58,8 @@ def get_fields(s_id): "label": i.label, "type": i.type, "number": i.number, - "value": value + "value": value, + "id": i.id, } # append the fields to array # use copy() to avoid overwriting @@ -154,14 +156,64 @@ def report_detail(request, report_pk): # update a section with new data @api_view(['PUT']) def section(request, report_pk, section_pk): - data = { - "message": "Updated report {0}, section {1}.".format(report_pk, section_pk), - "fields": { - "international": True, - "travel_date": "2012-04-23T18:25:43.511Z", - "fare": "1024.99", - "lowest_fare_screenshot": "image", - } - } + json_input = { + "fields": [ + { + "id": 178, + "value": "2016-05-22", + "type": "date" + }, + { + "id": 179, + "value": "2016-05-22", + "type": "date" + }, + { + "id": 180, + "value": 3.14, + "type": "decimal" + }, + { + "id": 181, + "value": 10000, + "type": "integer" + }, + { + "id": 182, + "value": True, + "type": "boolean" + }, + ] +} - return JsonResponse(data) + ''' + 1) decode JSON object into dictionaries + 2) iterate through fields (for loop)? + 3) in each iteration, check for data type + 4) in the datatype, update the database + 4a) update = field_set.get(id=request.data.id) + 4b) update.data_type = request.data["value"] + ''' + + # print("request data: {}".format(type(request.body))) + # json.loads() + + for v in json_input["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"] + + 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 894a6e76b6ba52528ec81376750c7f6dad32f04f..50db6ebfb3d28517a933f8650b2430a921d3e424 100644 GIT binary patch delta 1858 zcma)6eQZ-z6u;-*ZhhU>!U!9LvaJYYtFY4d`rY9Kf)28_iwP1w9NSy_I?J}U>pC|y z5#IO+F~Z88@foHdhA8MXgNN-z9dY76V1fokAqFyH03o7(A!ZT1uib#CiT-iVueax% z-#uUNY#YhnHjW2|Rt&>NyugV3($C@t{lr+qkM$FK{2it^bs3{@DV~M0uYABT9 zlybfB*1}?&iL-gFR;4{s!Mj14M*F_4x1tn_7Nz4Z1wn~F3KDPBN86^jU|Fip81&DhqHw zA{}Ht`GKs$7jZwy;1l>B8Bk12085+G3(X6NA6mPU9_tnd8;%7d(QsSG=APEB2p{k4 z;M&@HI)j~h)kr#X!K8ejHs_UPdCwwpl^iCYlQ5|wbwr16lAZW09#V?u?#0s3XhnHB zSq@X-aju8DZnwMKR^_MB*~NNFMUWT44&=pS6050FoL{|+mELb_!H`p05VGJg=%q@N zV)>>Xv~@*!{vBn@rOu2gb9om$0?OEh31&sOMesO70?*l6c)P%cgLb#a)56*u4iC%Q zS(n4ghg=@cIu#Q8@E}q%yIcA5%0*K3e|e7osOe=ifD+hINt%l)rzg*S+?*&!d=15I*c2TWk6PdanJ zL5!vKvNZ}NV9Xqe!g^RlIj5mI1dT9*oF@Hb4bjk!9>7s-hr4hbT}6AS+Kg->C-3V5 zqr9ve2C=0>jwfKI{AMeZXdS^=S8{cW{8|iE*#NUE)$&sPRJ0)>&L?QVLbitL z=M3a1B1h?pI7qZ>#K#S&4dfU5z%y?u!iU(^#$Le8nd}Wp|0*wG;?{s%IGw4oY!IV rvNnslSzONaE1=bs5t^GoPmrF_OUhaP1h_|ORkHD2@xgGw)&Ww6PMz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