Updated functionalities
This commit is contained in:
+33
-12
@@ -4,7 +4,7 @@ import uuid
|
||||
from datetime import datetime
|
||||
from app.utils.time_utils import now_eastern
|
||||
from flask import (Blueprint, render_template, redirect, url_for,
|
||||
flash, request, current_app, jsonify, Response)
|
||||
flash, request, current_app, jsonify, Response, abort)
|
||||
from flask_login import login_required, current_user
|
||||
from app import db
|
||||
from app.models.inspection import (Inspection, InspectionTemplate,
|
||||
@@ -218,7 +218,8 @@ def index():
|
||||
facilities=facilities,
|
||||
status_filter=status_filter,
|
||||
facility_filter=facility_filter,
|
||||
follow_up_filter=follow_up_filter)
|
||||
follow_up_filter=follow_up_filter,
|
||||
now=now_eastern())
|
||||
|
||||
|
||||
# ── Start ─────────────────────────────────────────────────────────────────────
|
||||
@@ -246,7 +247,9 @@ def start():
|
||||
form.area_id.choices = [(0, '— No specific area —')] + [(a.id, a.name) for a in areas]
|
||||
|
||||
if form.validate_on_submit():
|
||||
template = InspectionTemplate.query.get_or_404(form.template_id.data)
|
||||
template = db.session.get(InspectionTemplate, form.template_id.data)
|
||||
if template is None:
|
||||
abort(404)
|
||||
|
||||
if not template.get_form_schema():
|
||||
flash('This template has no form fields yet. Please build the form in the template editor first.', 'warning')
|
||||
@@ -290,7 +293,9 @@ def areas_for_facility(facility_id):
|
||||
@bp.route('/<int:inspection_id>/execute', methods=['GET', 'POST'])
|
||||
@login_required
|
||||
def execute(inspection_id):
|
||||
inspection = Inspection.query.get_or_404(inspection_id)
|
||||
inspection = db.session.get(Inspection, inspection_id)
|
||||
if inspection is None:
|
||||
abort(404)
|
||||
|
||||
if current_user.role == 'inspector' and inspection.inspector_id != current_user.id:
|
||||
flash('Access denied.', 'danger')
|
||||
@@ -430,7 +435,9 @@ def _save_draft(inspection, responses):
|
||||
@bp.route('/<int:inspection_id>/save-draft', methods=['POST'])
|
||||
@login_required
|
||||
def save_draft_ajax(inspection_id):
|
||||
inspection = Inspection.query.get_or_404(inspection_id)
|
||||
inspection = db.session.get(Inspection, inspection_id)
|
||||
if inspection is None:
|
||||
abort(404)
|
||||
|
||||
if current_user.role == 'inspector' and inspection.inspector_id != current_user.id:
|
||||
return jsonify({'ok': False, 'error': 'Access denied'}), 403
|
||||
@@ -466,7 +473,9 @@ def save_draft_ajax(inspection_id):
|
||||
@bp.route('/<int:inspection_id>')
|
||||
@login_required
|
||||
def view(inspection_id):
|
||||
inspection = Inspection.query.get_or_404(inspection_id)
|
||||
inspection = db.session.get(Inspection, inspection_id)
|
||||
if inspection is None:
|
||||
abort(404)
|
||||
|
||||
if current_user.role == 'inspector' and inspection.inspector_id != current_user.id:
|
||||
flash('Access denied.', 'danger')
|
||||
@@ -665,7 +674,9 @@ def view(inspection_id):
|
||||
@bp.route('/<int:inspection_id>/flag-issue', methods=['GET', 'POST'])
|
||||
@login_required
|
||||
def flag_issue(inspection_id):
|
||||
inspection = Inspection.query.get_or_404(inspection_id)
|
||||
inspection = db.session.get(Inspection, inspection_id)
|
||||
if inspection is None:
|
||||
abort(404)
|
||||
|
||||
if current_user.role == 'inspector' and inspection.inspector_id != current_user.id:
|
||||
flash('Access denied.', 'danger')
|
||||
@@ -751,7 +762,9 @@ def flag_issue(inspection_id):
|
||||
@login_required
|
||||
def export_pdf(inspection_id):
|
||||
"""Generate and stream a PDF report for the given inspection."""
|
||||
inspection = Inspection.query.get_or_404(inspection_id)
|
||||
inspection = db.session.get(Inspection, inspection_id)
|
||||
if inspection is None:
|
||||
abort(404)
|
||||
|
||||
if current_user.role == 'inspector' and inspection.inspector_id != current_user.id:
|
||||
flash('Access denied.', 'danger')
|
||||
@@ -821,7 +834,9 @@ def export_pdf(inspection_id):
|
||||
@supervisor_required
|
||||
def flag_followup(inspection_id):
|
||||
"""Mark an inspection as requiring a follow-up re-inspection."""
|
||||
inspection = Inspection.query.get_or_404(inspection_id)
|
||||
inspection = db.session.get(Inspection, inspection_id)
|
||||
if inspection is None:
|
||||
abort(404)
|
||||
note = request.form.get('follow_up_note', '').strip() or None
|
||||
|
||||
inspection.follow_up_required = True
|
||||
@@ -844,7 +859,9 @@ def flag_followup(inspection_id):
|
||||
@supervisor_required
|
||||
def clear_followup(inspection_id):
|
||||
"""Clear the follow-up required flag once actioned."""
|
||||
inspection = Inspection.query.get_or_404(inspection_id)
|
||||
inspection = db.session.get(Inspection, inspection_id)
|
||||
if inspection is None:
|
||||
abort(404)
|
||||
inspection.follow_up_required = False
|
||||
inspection.follow_up_note = None
|
||||
db.session.commit()
|
||||
@@ -863,7 +880,9 @@ def reinspect(inspection_id):
|
||||
"""Pre-fill the Start Inspection form with the same template/facility,
|
||||
linking the new inspection to the parent via parent_inspection_id."""
|
||||
from flask import session
|
||||
parent = Inspection.query.get_or_404(inspection_id)
|
||||
parent = db.session.get(Inspection, inspection_id)
|
||||
if parent is None:
|
||||
abort(404)
|
||||
|
||||
if current_user.role == 'customer':
|
||||
flash('Access denied.', 'danger')
|
||||
@@ -886,7 +905,9 @@ def reinspect(inspection_id):
|
||||
@login_required
|
||||
@supervisor_required
|
||||
def delete(inspection_id):
|
||||
inspection = Inspection.query.get_or_404(inspection_id)
|
||||
inspection = db.session.get(Inspection, inspection_id)
|
||||
if inspection is None:
|
||||
abort(404)
|
||||
|
||||
insp_id = inspection.id
|
||||
insp_date = inspection.inspection_date.strftime('%Y-%m-%d %H:%M')
|
||||
|
||||
Reference in New Issue
Block a user