From 816423651329c89d8c0c4e73144522b29096c1a4 Mon Sep 17 00:00:00 2001 From: Rupika Date: Thu, 14 Feb 2019 13:26:26 -0800 Subject: [PATCH] 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