import re from flask import Blueprint, render_template, request, redirect, url_for, flash, session from app.models import Standard from app.routes.auth import role_required standards_bp = Blueprint('standards', __name__) @standards_bp.route('/') @role_required('review') def list_standards(): """List all standards""" standards = Standard.get_all() return render_template('standards_list.html', standards=standards, user=session) @standards_bp.route('/new') @role_required('review') def new_standard(): """Display form to create new standard""" return render_template('standards_form.html', user=session) @standards_bp.route('/', methods=['POST']) @role_required('review') def create_standard(): """Handle new standard creation""" try: # Create the standard standard = Standard.create( make=request.form['make'], model=request.form['model'], description=request.form['description'], uncertainty=request.form['uncertainty'], calibrated_on=request.form['calibrated_on'], calibration_due=request.form['calibration_due'], support_name=request.form['support_name'], support_email=request.form['support_email'], support_phone=request.form['support_phone'], support_address=request.form['support_address'] ) flash('Standard created successfully', 'success') return redirect(url_for('standards.list_standards')) except Exception as e: flash(f'Error creating standard: {str(e)}', 'danger') return redirect(url_for('standards.new_standard')) @standards_bp.route('/') @role_required('review') def view_standard(standard_id): """View details of a single standard""" standard = Standard.get_by_id(standard_id) if not standard: flash('Standard not found', 'danger') return redirect(url_for('standards.list_standards')) return render_template('standards_view.html', standard=standard, user=session)