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"} } diff --git a/back/backend/views.py b/back/backend/views.py index 7c82e53..6de2b1e 100644 --- a/back/backend/views.py +++ b/back/backend/views.py @@ -229,9 +229,67 @@ def section(request, report_pk, section_pk): update.save() + # 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.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) +# 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 == 0.0 or + 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 == 0 or + 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