Jul 21 - Update QR code destination page, shows recent inspection cleaning quality
This commit is contained in:
+34
-11
@@ -110,12 +110,34 @@ def _rating_label(score):
|
||||
return ('Needs attention', 'danger')
|
||||
|
||||
|
||||
def _recent_rows(inspections):
|
||||
"""Shape recent completed inspections for the occupant page.
|
||||
|
||||
Each row carries the date and the occupant-friendly quality label/colour.
|
||||
The raw score percentage is deliberately NOT included in the payload — the
|
||||
occupant sees the quality label only, so the number cannot leak into the
|
||||
rendered page. Also excludes inspector names, template/checklist names,
|
||||
and any per-item detail (occupant-safe).
|
||||
"""
|
||||
rows = []
|
||||
for i in inspections:
|
||||
score = float(i.overall_score) if i.overall_score is not None else None
|
||||
label, colour = _rating_label(score) # None -> 'Not yet rated'
|
||||
rows.append({
|
||||
'date': i.inspection_date,
|
||||
'label': label,
|
||||
'colour': colour,
|
||||
})
|
||||
return rows
|
||||
|
||||
|
||||
def _build_summary(facility: Facility) -> dict:
|
||||
"""Assemble the occupant-facing summary for a facility.
|
||||
|
||||
Occupant-safe (rule 74): aggregate rating, counts, a score trend, and
|
||||
recent inspection DATES only — no checklist/template names, no
|
||||
per-inspection scores, no issue descriptions, and no severity/SLA detail.
|
||||
recent inspections showing date + quality LABEL only (no score
|
||||
percentage) — no checklist/template names, no inspector names, no issue
|
||||
descriptions, and no per-item or severity/SLA detail.
|
||||
"""
|
||||
fid = facility.id
|
||||
now = now_eastern()
|
||||
@@ -172,7 +194,8 @@ def _build_summary(facility: Facility) -> dict:
|
||||
else:
|
||||
trend_delta = None
|
||||
|
||||
# Recent inspection DATES only (no checklist names, no scores)
|
||||
# Recent inspections: date + score + quality label (no checklist/template
|
||||
# names, no inspector names, no per-item detail).
|
||||
recent = (
|
||||
Inspection.query
|
||||
.filter(Inspection.facility_id == fid,
|
||||
@@ -181,7 +204,7 @@ def _build_summary(facility: Facility) -> dict:
|
||||
.limit(5)
|
||||
.all()
|
||||
)
|
||||
recent_dates = [i.inspection_date for i in recent]
|
||||
recent_inspections = _recent_rows(recent)
|
||||
|
||||
# Open-issue COUNT (linked directly or via an area) — no details exposed
|
||||
open_issue_count = (
|
||||
@@ -213,9 +236,9 @@ def _build_summary(facility: Facility) -> dict:
|
||||
'inspections_90': inspections_90,
|
||||
'open_issue_count': open_issue_count,
|
||||
'resolved_90': resolved_90,
|
||||
'trend_delta': trend_delta,
|
||||
'last_inspected': last_insp.inspection_date if last_insp else None,
|
||||
'recent_dates': recent_dates,
|
||||
'trend_delta': trend_delta,
|
||||
'last_inspected': last_insp.inspection_date if last_insp else None,
|
||||
'recent_inspections': recent_inspections,
|
||||
}
|
||||
|
||||
|
||||
@@ -297,7 +320,7 @@ def _build_area_summary(area, facility) -> dict:
|
||||
.limit(5)
|
||||
.all()
|
||||
)
|
||||
recent_dates = [i.inspection_date for i in recent]
|
||||
recent_inspections = _recent_rows(recent)
|
||||
|
||||
open_issue_count = (
|
||||
Issue.query
|
||||
@@ -326,9 +349,9 @@ def _build_area_summary(area, facility) -> dict:
|
||||
'inspections_90': inspections_90,
|
||||
'open_issue_count': open_issue_count,
|
||||
'resolved_90': resolved_90,
|
||||
'trend_delta': trend_delta,
|
||||
'last_inspected': last_insp.inspection_date if last_insp else None,
|
||||
'recent_dates': recent_dates,
|
||||
'trend_delta': trend_delta,
|
||||
'last_inspected': last_insp.inspection_date if last_insp else None,
|
||||
'recent_inspections': recent_inspections,
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user