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())
|
||||
|
||||
|
||||
|
||||
+25
-8
@@ -478,16 +478,33 @@ def unfollow(issue_id):
|
||||
|
||||
@bp.route('/new', methods=['GET', 'POST'])
|
||||
@login_required
|
||||
@supervisor_required
|
||||
def create():
|
||||
from app.models.project import Project
|
||||
form = IssueForm()
|
||||
facilities = Facility.query.filter_by(active=True).order_by(Facility.name).all()
|
||||
projects = Project.query.filter_by(active=True).order_by(Project.name).all()
|
||||
staff = User.query.filter(User.role.in_(['admin', 'director', 'inspector'])).order_by(User.username).all()
|
||||
if current_user.role not in ('admin', 'director', 'customer'):
|
||||
abort(403)
|
||||
|
||||
form.facility_id.choices = [(f.id, f.name) for f in facilities]
|
||||
form.assigned_to.choices = [(0, '— Unassigned —')] + [(u.id, u.username) for u in staff]
|
||||
from app.models.project import Project, CustomerAssignment
|
||||
form = IssueForm()
|
||||
|
||||
if current_user.role == 'customer':
|
||||
cids = get_customer_scope(current_user) or []
|
||||
facilities = (Facility.query
|
||||
.filter(Facility.id.in_(cids), Facility.active == True)
|
||||
.order_by(Facility.name).all()) if cids else []
|
||||
assigned_pids = {
|
||||
a.project_id for a in
|
||||
CustomerAssignment.query.filter_by(user_id=current_user.id).all()
|
||||
}
|
||||
projects = Project.query.filter(
|
||||
Project.active == True, Project.id.in_(assigned_pids)
|
||||
).order_by(Project.name).all()
|
||||
staff = []
|
||||
else:
|
||||
facilities = Facility.query.filter_by(active=True).order_by(Facility.name).all()
|
||||
projects = Project.query.filter_by(active=True).order_by(Project.name).all()
|
||||
staff = User.query.filter(User.role.in_(['admin', 'director', 'inspector'])).order_by(User.username).all()
|
||||
|
||||
form.facility_id.choices = [(f.id, f.name) for f in facilities]
|
||||
form.assigned_to.choices = [(0, '— Unassigned —')] + [(u.id, u.username) for u in staff]
|
||||
|
||||
# On POST validation error: identify which contract the submitted facility
|
||||
# belongs to so the contract selector can be restored on re-render.
|
||||
|
||||
Reference in New Issue
Block a user