Aug 5 - Update code to follow up ST - Fix pending items
This commit is contained in:
@@ -340,18 +340,47 @@ def index():
|
||||
if current_user.role == 'customer':
|
||||
abort(403)
|
||||
|
||||
q = InspectionSchedule.query
|
||||
if current_user.role == 'inspector':
|
||||
q = q.filter(InspectionSchedule.inspector_id == current_user.id)
|
||||
# Two tabs (phase51): Pending = schedules still producing occurrences
|
||||
# (active); Completed = closed ones — fulfilled one-times, recurring
|
||||
# schedules past their end date, and manually paused ones. The partition is
|
||||
# exhaustive and non-overlapping on `active`, so every schedule appears in
|
||||
# exactly one tab and none can be lost; the in-row Status badge
|
||||
# (Active / Ended / Paused) disambiguates the closed ones.
|
||||
#
|
||||
# Before this the list was a single table sorted active-first, which meant a
|
||||
# tenant with years of one-time follow-ups buried the handful of live
|
||||
# schedules an inspector actually needed to act on.
|
||||
tab = request.args.get('tab', 'pending')
|
||||
if tab not in ('pending', 'completed'):
|
||||
tab = 'pending'
|
||||
|
||||
base = InspectionSchedule.query
|
||||
# Inspectors see only their own assignments; managers see everything.
|
||||
if current_user.role == 'inspector':
|
||||
base = base.filter(InspectionSchedule.inspector_id == current_user.id)
|
||||
|
||||
# Counts are computed on the same scoped query, so the badges match what the
|
||||
# viewer can actually open.
|
||||
pending_count = base.filter(InspectionSchedule.active.is_(True)).count()
|
||||
completed_count = base.filter(InspectionSchedule.active.is_(False)).count()
|
||||
|
||||
if tab == 'pending':
|
||||
schedules = (base.filter(InspectionSchedule.active.is_(True))
|
||||
.order_by(InspectionSchedule.next_run_at.asc(),
|
||||
InspectionSchedule.name).all())
|
||||
else:
|
||||
# Most recently completed first. A schedule switched off before it ever
|
||||
# ran has a NULL last_completed_at and sorts last under DESC.
|
||||
schedules = (base.filter(InspectionSchedule.active.is_(False))
|
||||
.order_by(InspectionSchedule.last_completed_at.desc(),
|
||||
InspectionSchedule.next_run_at.desc(),
|
||||
InspectionSchedule.name).all())
|
||||
|
||||
schedules = q.order_by(
|
||||
InspectionSchedule.active.desc(),
|
||||
InspectionSchedule.next_run_at.asc(),
|
||||
InspectionSchedule.name,
|
||||
).all()
|
||||
now = now_eastern()
|
||||
return render_template('inspection_schedules/index.html',
|
||||
schedules=schedules, now=now, today=now.date())
|
||||
schedules=schedules, now=now, today=now.date(),
|
||||
tab=tab, pending_count=pending_count,
|
||||
completed_count=completed_count)
|
||||
|
||||
|
||||
def _form_choices():
|
||||
|
||||
Reference in New Issue
Block a user