06/09 Add Inspecter filters, and allow customer to flag issue
This commit is contained in:
@@ -232,6 +232,11 @@ def index():
|
||||
facility_filter = request.args.get('facility_id', '')
|
||||
follow_up_filter = request.args.get('follow_up', '')
|
||||
contract_filter = request.args.get('contract_id', '')
|
||||
date_from_filter = request.args.get('date_from', '')
|
||||
date_to_filter = request.args.get('date_to', '')
|
||||
score_min_filter = request.args.get('score_min', '')
|
||||
score_max_filter = request.args.get('score_max', '')
|
||||
inspector_filter = request.args.get('inspector_id', '')
|
||||
|
||||
if status_filter:
|
||||
q = q.filter(Inspection.status == status_filter)
|
||||
@@ -247,6 +252,29 @@ def index():
|
||||
Inspection.follow_up_required == True,
|
||||
Inspection.status == 'completed',
|
||||
).filter(~Inspection.follow_ups.any())
|
||||
if date_from_filter:
|
||||
try:
|
||||
q = q.filter(Inspection.inspection_date >= datetime.strptime(date_from_filter, '%Y-%m-%d'))
|
||||
except ValueError:
|
||||
date_from_filter = ''
|
||||
if date_to_filter:
|
||||
try:
|
||||
_dt = datetime.strptime(date_to_filter, '%Y-%m-%d').replace(hour=23, minute=59, second=59)
|
||||
q = q.filter(Inspection.inspection_date <= _dt)
|
||||
except ValueError:
|
||||
date_to_filter = ''
|
||||
if score_min_filter:
|
||||
try:
|
||||
q = q.filter(Inspection.overall_score >= float(score_min_filter))
|
||||
except ValueError:
|
||||
score_min_filter = ''
|
||||
if score_max_filter:
|
||||
try:
|
||||
q = q.filter(Inspection.overall_score <= float(score_max_filter))
|
||||
except ValueError:
|
||||
score_max_filter = ''
|
||||
if inspector_filter.isdigit() and current_user.role != 'inspector':
|
||||
q = q.filter(Inspection.inspector_id == int(inspector_filter))
|
||||
|
||||
inspections = q.paginate(page=page, per_page=20, error_out=False)
|
||||
|
||||
@@ -276,14 +304,28 @@ def index():
|
||||
else:
|
||||
projects = Project.query.filter_by(active=True).order_by(Project.name).all()
|
||||
|
||||
# Inspector dropdown — shown to all roles except inspector (they only see their own)
|
||||
if current_user.role != 'inspector':
|
||||
inspectors = (User.query
|
||||
.filter(User.role == 'inspector', User.active == True)
|
||||
.order_by(User.full_name, User.username).all())
|
||||
else:
|
||||
inspectors = []
|
||||
|
||||
return render_template('inspections/list.html',
|
||||
inspections=inspections,
|
||||
facilities=facilities,
|
||||
projects=projects,
|
||||
inspectors=inspectors,
|
||||
status_filter=status_filter,
|
||||
facility_filter=facility_filter,
|
||||
follow_up_filter=follow_up_filter,
|
||||
contract_filter=contract_filter,
|
||||
date_from_filter=date_from_filter,
|
||||
date_to_filter=date_to_filter,
|
||||
score_min_filter=score_min_filter,
|
||||
score_max_filter=score_max_filter,
|
||||
inspector_filter=inspector_filter,
|
||||
now=now_eastern())
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user