Improve on the template, most things work???
This commit is contained in:
parent
c0f9876184
commit
46fa0d1ae5
19 changed files with 396 additions and 181 deletions
54
app/routes/admin.py
Normal file
54
app/routes/admin.py
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
from flask import Blueprint, render_template, request, redirect, url_for, flash
|
||||
from app.forms import UserForm, RepairBayForm
|
||||
from app.models import User, RepairBay
|
||||
from app import db
|
||||
|
||||
admin_bp = Blueprint('admin', __name__)
|
||||
|
||||
@admin_bp.route('/admin/dashboard', methods=['GET', 'POST'])
|
||||
def dashboard():
|
||||
if request.method == 'POST':
|
||||
# Handle form submission for creating/removing users or repair bays
|
||||
pass # Implementation will go here
|
||||
|
||||
users = User.query.all()
|
||||
repair_bays = RepairBay.query.all()
|
||||
return render_template('admin/dashboard.html', users=users, repair_bays=repair_bays)
|
||||
|
||||
@admin_bp.route('/admin/user/create', methods=['GET', 'POST'])
|
||||
def create_user():
|
||||
form = UserForm()
|
||||
if form.validate_on_submit():
|
||||
new_user = User(username=form.username.data, email=form.email.data)
|
||||
db.session.add(new_user)
|
||||
db.session.commit()
|
||||
flash('User created successfully!', 'success')
|
||||
return redirect(url_for('admin.dashboard'))
|
||||
return render_template('admin/create_user.html', form=form)
|
||||
|
||||
@admin_bp.route('/admin/user/delete/<int:user_id>', methods=['POST'])
|
||||
def delete_user(user_id):
|
||||
user = User.query.get_or_404(user_id)
|
||||
db.session.delete(user)
|
||||
db.session.commit()
|
||||
flash('User deleted successfully!', 'success')
|
||||
return redirect(url_for('admin.dashboard'))
|
||||
|
||||
@admin_bp.route('/admin/repair_bay/create', methods=['GET', 'POST'])
|
||||
def create_repair_bay():
|
||||
form = RepairBayForm()
|
||||
if form.validate_on_submit():
|
||||
new_bay = RepairBay(name=form.name.data)
|
||||
db.session.add(new_bay)
|
||||
db.session.commit()
|
||||
flash('Repair bay created successfully!', 'success')
|
||||
return redirect(url_for('admin.dashboard'))
|
||||
return render_template('admin/create_repair_bay.html', form=form)
|
||||
|
||||
@admin_bp.route('/admin/repair_bay/delete/<int:bay_id>', methods=['POST'])
|
||||
def delete_repair_bay(bay_id):
|
||||
bay = RepairBay.query.get_or_404(bay_id)
|
||||
db.session.delete(bay)
|
||||
db.session.commit()
|
||||
flash('Repair bay deleted successfully!', 'success')
|
||||
return redirect(url_for('admin.dashboard'))
|
||||
Loading…
Add table
Add a link
Reference in a new issue