From a2deb2b1bd5fec6bbf69c4b3e5203412a8e531c9 Mon Sep 17 00:00:00 2001 From: Rupika Date: Wed, 13 Feb 2019 23:36:29 -0800 Subject: [PATCH] updated database with field_type --- .../migrations/0007_merge_20190213_2318.py | 14 ++++++ back/backend/views.py | 41 +++++++++--------- back/db.sqlite3 | Bin 105472 -> 105472 bytes 3 files changed, 35 insertions(+), 20 deletions(-) create mode 100644 back/backend/migrations/0007_merge_20190213_2318.py diff --git a/back/backend/migrations/0007_merge_20190213_2318.py b/back/backend/migrations/0007_merge_20190213_2318.py new file mode 100644 index 0000000..aa0cb2c --- /dev/null +++ b/back/backend/migrations/0007_merge_20190213_2318.py @@ -0,0 +1,14 @@ +# Generated by Django 2.1.5 on 2019-02-14 07:18 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('backend', '0006_auto_20190213_1719'), + ('backend', '0006_auto_20190213_2113'), + ] + + operations = [ + ] diff --git a/back/backend/views.py b/back/backend/views.py index 452ee82..04fc6dd 100644 --- a/back/backend/views.py +++ b/back/backend/views.py @@ -157,59 +157,60 @@ def report_detail(request, report_pk): def section(request, report_pk, section_pk): for key in request.data: - update_field = Field.objects.get(section_id=section_pk, field_name=key) + # get the matching field object + update = Field.objects.get(section_id=section_pk, field_name=key) - if update_field.type == "boolean": + if update.field_type == "boolean": # flight check if request.data[key] == "on": - update_field.data_bool = True + update.data_bool = True elif request.data[key] == "off": - update_field.data_bool = False + update.data_bool = False # everything else else: - update_field.data_bool = request.data[key] + update.data_bool = request.data[key] - if update_field.type == "decimal": + if update.field_type == "decimal": # initialize to 0 if ( request.data[key] == "" or request.data[key] is None ): - update_field.data_decimal = 0.0 + update.data_decimal = 0.0 else: - update_field.data_decimal = request.data[key] + update.data_decimal = request.data[key] - if update_field.type == "date": + if update.field_type == "date": # initialize to today's date if ( request.data[key] == "" or request.data[key] is None ): - # update_field.data_date = datetime.date.today() - update_field.data_date = None + update.data_date = None else: - update_field.data_date = request.data[key] + update.data_date = request.data[key] - if update_field.type == "file": - update_field.data_file = request.data[key] + if update.field_type == "file": + update.data_file = request.data[key] - if update_field.type == "string": - update_field.data_string = request.data[key] + if update.field_type == "string": + update.data_string = request.data[key] - if update_field.type == "integer": + if update.field_type == "integer": # initialize to 0 if ( request.data[key] == "" or request.data[key] is None ): - update_field.data_integer = 0 + update.data_integer = 0 else: - update_field.data_integer = request.data[key] + update.data_integer = request.data[key] - update_field.save() + update.save() data = { "message": "Updated report {0}, section {1}.".format(report_pk, section_pk), + "request_data": request.data } return JsonResponse(data) diff --git a/back/db.sqlite3 b/back/db.sqlite3 index 52e2ecd33b88e7002ab103f534d060a875cfa6ab..df940de7c8c054f4ee96162876249a47ea35ec8b 100644 GIT binary patch delta 3457 zcmeHKOHP5Flh?~(#E0T(ZrE$*{B$c8nNi6 zCT$l?+eyffj=Jm*=%&LYuxx%or|Zmg(oM7KHjBRRHL@ky7S2pN(@hpvwyyP^$ES18 z`Mh(~xpUOHH`JFy2<7$Fi9f%(>kZ;f-!IM%eAi3e$5*uU-DZMnTT%}0QxlF(?&Se0 zL2Gv}!O(t(^ERB`zvn#vQvV<&Kw8YKOT}y|CrgEFDy0;%o1Z>$9zJox;M^%;Nv6FMFzRSMbn4? z++1Q!%B=h3BAXResf}EG8GS27?hIt?DuX;-RisBpD%)xW>N7#{UOhI+pa?yrdv$SI z-!crBeI<*7_!aD+7Mh2fmNvzbx?Peg4k+Tlo2~BEIS9SWpwSw3l)EBfpeZSDsj^`~ zy~anz-eHid%ZTd@u_Wodd2{%?k^TH-2F=$paC6%CcYrOY6{R4FMXy{`rBYE;Wu+(< z3{ZT5K|Xp=PkR(+w57_&kFg0^{b)-q$;JGuS!3J4#^z6=n~*V{aaZ0{6T0V`(LG*A z_uDP$_Sn)rdotY~8@gv~>Gsso{ZA$*M7M$6D36ee8A#U{$ zcxwpLH|(sJ`9|v#*Rgd|a*cg$+-g4hek)lsZX;`EdRI>%a>D8+xzdcti8>;e?NUun zG^XlbYC)vm8p8B7JL{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