Fixed bugs in rules returning strings.

This commit is contained in:
kououken 2019-02-20 17:05:36 -08:00
parent bc7fc340f5
commit 9ea335d68f
4 changed files with 10 additions and 7 deletions

View file

@ -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):
"""

View file

@ -70,13 +70,13 @@ general_section = Section(
title="General Info",
html_description="<p>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.</p><p>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.</p>",
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"},
}
)

View file

@ -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:

Binary file not shown.