Create the template for the Flask framework
This commit is contained in:
parent
db65646400
commit
c0f9876184
14 changed files with 266 additions and 0 deletions
38
app/routes/repair.py
Normal file
38
app/routes/repair.py
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
from flask import Blueprint, render_template, request, redirect, url_for, flash, current_app
|
||||
from flask_login import login_required, current_user
|
||||
from app.models import db, RepairJob, Customer, Technician, AuditLog
|
||||
from app.utils.barcode import generate_barcode
|
||||
|
||||
repair_bp = Blueprint('repair', __name__, url_prefix='/repairs')
|
||||
|
||||
@repair_bp.route('/new', methods=['GET', 'POST'])
|
||||
@login_required
|
||||
def new_repair():
|
||||
if request.method == 'POST':
|
||||
# ... get form data ...
|
||||
repair = RepairJob(
|
||||
device=request.form['device'],
|
||||
description=request.form['description'],
|
||||
customer_id=request.form['customer_id'],
|
||||
technician_id=request.form.get('technician_id'),
|
||||
)
|
||||
db.session.add(repair)
|
||||
db.session.commit()
|
||||
# Generate and save barcode image
|
||||
barcode_path = generate_barcode(repair.id, repair.tracking_number)
|
||||
repair.barcode_path = barcode_path
|
||||
db.session.commit()
|
||||
# Audit log
|
||||
audit = AuditLog(user_id=current_user.id, action='Created repair', details=f"Repair ID {repair.id}")
|
||||
db.session.add(audit)
|
||||
db.session.commit()
|
||||
flash('Repair job created!')
|
||||
return redirect(url_for('repair.detail', repair_id=repair.id))
|
||||
# ... render form ...
|
||||
return render_template('repairs/new.html')
|
||||
|
||||
@repair_bp.route('/<int:repair_id>')
|
||||
@login_required
|
||||
def detail(repair_id):
|
||||
repair = RepairJob.query.get_or_404(repair_id)
|
||||
return render_template('repairs/detail.html', repair=repair)
|
||||
Loading…
Add table
Add a link
Reference in a new issue