diff --git a/back/backend/models.py b/back/backend/models.py index 7859a08..69db8ee 100644 --- a/back/backend/models.py +++ b/back/backend/models.py @@ -79,6 +79,7 @@ class Field(models.Model): return "{}".format(self.data_string) elif self.field_type == "integer": return "{}".format(self.data_integer) + return "Invalid type" def get_datatype(self): """ diff --git a/back/backend/policy.py b/back/backend/policy.py index 2674cc7..df95286 100644 --- a/back/backend/policy.py +++ b/back/backend/policy.py @@ -70,13 +70,13 @@ general_section = Section( title="General Info", html_description="

Each section of this report is designed to guide you through the reimbursement process. Please read through each and answer as many questions as you can that apply to you.

Be sure to click 'Save' after completing each section. Your entered data will be saved as you progress. You may also receive feedback from sections regarding policy restrictions and special requirements.

", fields={ - "before_trip": {"number": 0, "label": "Have you taken this trip already?", "field_type": "boolean"}, + "after_trip": {"number": 0, "label": "Have you taken this trip already?", "field_type": "boolean"}, } ) general_section.add_rule( title="Pre-trip / post-trip check", - rule=lambda report, fields: None if fields['before_trip'] else "If you have already take the trip your request will require special approval by the administrator. You may skip the following 'Pre-trip Planning' section." + rule=lambda report, fields: "If you have already take the trip your request will require special approval by the administrator. You may skip the following 'Pre-trip Planning' section." if fields['after_trip'] else None ) pol.add_section(general_section) @@ -193,7 +193,7 @@ lodging_section = Section( "cost": {"number": 1, "label": "Total cost for lodging", "field_type": "decimal"}, "check_in_date": {"number": 2, "label": "Check-in date", "field_type": "date"}, "check_out_date": {"number": 3, "label": "Check-out date", "field_type": "date"}, - "invoice_screenshot": {"number": 4, "label": "Screenshot of invoice", "field_type": "screenshot"}, + "invoice_screenshot": {"number": 4, "label": "Screenshot of invoice", "field_type": "file"}, } ) diff --git a/back/backend/views.py b/back/backend/views.py index 1216bee..bd4a9ec 100644 --- a/back/backend/views.py +++ b/back/backend/views.py @@ -53,10 +53,11 @@ def get_sections(r_id): for rule in rules: try: named_fields = generate_named_fields_for_section(data['fields']) - if not rule['rule'](data, named_fields): + result = rule['rule'](data, named_fields) + if not result is None: info = { "label": rule['title'], - "rule_break_text": rule['rule_break_text'], + "rule_break_text": result, } data['rule_violations'].append(info) except Exception as e: @@ -342,10 +343,11 @@ def section(request, report_pk, section_pk): for rule in rules: try: named_fields = generate_named_fields_for_section(data['fields']) - if not rule['rule'](data, named_fields): + result = rule['rule'](data, named_fields) + if not result is None: info = { "label": rule['title'], - "rule_break_text": rule['rule_break_text'], + "rule_break_text": result, } data['rule_violations'].append(info) except Exception as e: diff --git a/back/db.sqlite3 b/back/db.sqlite3 index d3fa227..b0936b9 100644 Binary files a/back/db.sqlite3 and b/back/db.sqlite3 differ