From 816423651329c89d8c0c4e73144522b29096c1a4 Mon Sep 17 00:00:00 2001 From: Rupika Date: Thu, 14 Feb 2019 13:26:26 -0800 Subject: [PATCH 1/3] added logic for section complete check --- back/backend/views.py | 54 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/back/backend/views.py b/back/backend/views.py index 04fc6dd..aa85be2 100644 --- a/back/backend/views.py +++ b/back/backend/views.py @@ -208,9 +208,63 @@ def section(request, report_pk, section_pk): update.save() + # update section boolean to complete + complete = section_complete(section_pk) + if complete: + s = Section.objects.get(id=section_pk) + s.completed = True + s.save() + data = { "message": "Updated report {0}, section {1}.".format(report_pk, section_pk), "request_data": request.data } return JsonResponse(data) +# function checks if a field is filled and +# returns boolean accordingly +def section_complete(section_pk): + # grab field set + check_fields = Field.objects.filter(section_id=section_pk) + + # return true if any field is filled + for i in check_fields: + if i.field_type == "boolean": + if not( + i.data_bool == "" or + i.data_bool is None + ): + return True + elif i.field_type == "decimal": + if not( + i.data_decimal == "" or + i.data_decimal is None + ): + return True + elif i.field_type == "date": + if not( + i.data_date == "" or + i.data_date is None + ): + return True + elif i.field_type == "file": + if not( + i.data_file == "" or + i.data_file is None + ): + return True + elif i.field_type == "string": + if not( + i.data_string == "" or + i.data_string is None + ): + return True + elif i.field_type == "integer": + if not( + i.data_integer == "" or + i.data_integer is None + ): + return True + + # return false if no field is filled + return False \ No newline at end of file From 736f45001339750f2656e34c8920565fbdbf5273 Mon Sep 17 00:00:00 2001 From: Rupika Date: Thu, 14 Feb 2019 17:36:33 -0800 Subject: [PATCH 2/3] extra changes for testing section complete --- back/backend/views.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/back/backend/views.py b/back/backend/views.py index aa85be2..68b177f 100644 --- a/back/backend/views.py +++ b/back/backend/views.py @@ -210,13 +210,15 @@ def section(request, report_pk, section_pk): # update section boolean to complete complete = section_complete(section_pk) + s = Section.objects.get(id=section_pk) if complete: - s = Section.objects.get(id=section_pk) + # s = Section.objects.get(id=section_pk) s.completed = True s.save() data = { "message": "Updated report {0}, section {1}.".format(report_pk, section_pk), + "section completion": s.completed, "request_data": request.data } return JsonResponse(data) @@ -237,6 +239,7 @@ def section_complete(section_pk): return True elif i.field_type == "decimal": if not( + i.data_decimal == 0.0 or i.data_decimal == "" or i.data_decimal is None ): @@ -261,6 +264,7 @@ def section_complete(section_pk): return True elif i.field_type == "integer": if not( + i.data_integer == 0 or i.data_integer == "" or i.data_integer is None ): From 1f4cf8a43c3bdf6efe5c2fad742d51a09e3273a7 Mon Sep 17 00:00:00 2001 From: Rupika Date: Thu, 14 Feb 2019 19:28:21 -0800 Subject: [PATCH 3/3] changed per diem trip duration to integer from decimal --- back/backend/policy.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/back/backend/policy.py b/back/backend/policy.py index 7af3281..1628b57 100644 --- a/back/backend/policy.py +++ b/back/backend/policy.py @@ -128,7 +128,7 @@ per_diem_section = Section( html_description="

Enter info about meals and incidentals here.\nPer diem rates can be found at " "this link

", fields={ - "duration": {"label": "How many days was your trip?", "field_type": "decimal"}, + "duration": {"label": "How many days was your trip?", "field_type": "integer"}, "rate": {"label": "What is the per diem rate for your destination?", "field_type": "decimal"}, "cost": {"label": "Total Cost for meals and incidentals", "field_type": "decimal"} }