March 17 2026: form editor - add pass/fail element

This commit is contained in:
2026-03-17 12:09:40 -04:00
parent 46df092a61
commit 33166bbc6b
7 changed files with 85 additions and 8 deletions
+14 -3
View File
@@ -30,7 +30,7 @@ ALLOWED_EXTENSIONS = {'jpg', 'jpeg', 'png', 'gif'}
INPUT_FIELD_TYPES = {
'text', 'textarea', 'number', 'date', 'email',
'checkbox', 'checkbox_group', 'radio', 'select',
'rating', 'signature', 'image', 'table'
'rating', 'pass_fail', 'signature', 'image', 'table'
}
@@ -115,7 +115,7 @@ def _compute_score_from_form(form_fields, responses):
Derive an overall score from rating fields and checkbox pass/fail fields.
Returns a float 0100 or None if the form has no scoreable fields.
"""
scoreable = [f for f in form_fields if f['type'] in ('rating', 'checkbox', 'radio')]
scoreable = [f for f in form_fields if f['type'] in ('rating', 'checkbox', 'radio', 'pass_fail')]
if not scoreable:
return None
@@ -144,6 +144,13 @@ def _compute_score_from_form(form_fields, responses):
if val.lower() in ('pass', 'yes', 'ok', 'good', 'acceptable', 'compliant'):
earned += 1
elif field['type'] == 'pass_fail':
if not val:
continue
total += 1
if val.lower() in ('pass', 'yes', 'ok', 'good', 'acceptable', 'compliant'):
earned += 1
return round((earned / total) * 100, 2) if total else None
@@ -478,7 +485,7 @@ def view(inspection_id):
except (json.JSONDecodeError, TypeError):
pass
scoreable_types = ('rating', 'checkbox', 'radio')
scoreable_types = ('rating', 'checkbox', 'radio', 'pass_fail')
# Collect all text/textarea fields per row, keyed by (col, fid)
# so we can pick the leftmost non-empty value as the item name.
@@ -557,6 +564,10 @@ def view(inspection_id):
return 100.0 if val == 'true' else 0.0
if ft == 'radio':
return None if not val else 100.0
if ft == 'pass_fail':
if not val:
return None
return 100.0 if val.lower() in ('pass', 'yes', 'ok', 'good', 'acceptable', 'compliant') else 0.0
return None
cur_pct = _field_pct(cur_val, ftype)
+1 -1
View File
@@ -229,7 +229,7 @@ def save_form_schema(template_id):
'label': str(field.get('label', 'Untitled'))[:255],
'placeholder': str(field.get('placeholder', ''))[:255],
'required': bool(field.get('required', False)),
'options': field.get('options', []) if ftype in ('radio', 'checkbox_group', 'select') else [],
'options': field.get('options', []) if ftype in ('radio', 'checkbox_group', 'select', 'pass_fail') else [],
'help_text': str(field.get('help_text', ''))[:500],
'order': int(field.get('order', 0)),
# Grid position & size