More dynamic menu handling. Did a lot of stuff using Flask-Nav & Flask_Menu, but removed all of it becauses it became overly complex or the extensions were no longer in active development.
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
import uuid
|
||||
from datetime import datetime as dt, timezone as tz
|
||||
from flask import request, redirect, url_for, flash, render_template, Blueprint, session
|
||||
from flask_security import hash_password
|
||||
from flask_security import hash_password, current_user
|
||||
|
||||
from ..models.user import User, Tenant, Role, RolesUsers
|
||||
from ..extensions import db
|
||||
@@ -162,3 +162,44 @@ def edit_user(user_id):
|
||||
|
||||
form.roles.data = [role.id for role in user.roles]
|
||||
return render_template('user/edit_user.html', form=form, user_id=user_id)
|
||||
|
||||
|
||||
@user_bp.route('/select_tenant')
|
||||
def select_tenant():
|
||||
tenants = Tenant.query.all() # Fetch all tenants from the database
|
||||
return render_template('user/select_tenant.html', tenants=tenants)
|
||||
|
||||
|
||||
@user_bp.route('/handle_tenant_selection', methods=['POST'])
|
||||
def handle_tenant_selection():
|
||||
tenant_id = request.form['tenant_id']
|
||||
session['tenant_id'] = request.form['tenant_id']
|
||||
action = request.form['action']
|
||||
|
||||
if action == 'view_users':
|
||||
return redirect(url_for('user_bp.view_users', tenant_id=tenant_id))
|
||||
elif action == 'edit_tenant':
|
||||
return redirect(url_for('user_bp.edit_tenant', tenant_id=tenant_id))
|
||||
# Add more conditions for other actions
|
||||
return redirect(url_for('select_tenant'))
|
||||
|
||||
|
||||
@user_bp.route('/view_users/<tenant_id>')
|
||||
def view_users(tenant_id):
|
||||
print(tenant_id)
|
||||
tenant_id = int(tenant_id)
|
||||
users = User.query.filter_by(tenant_id=tenant_id).all()
|
||||
|
||||
# Render the users in a template
|
||||
return render_template('user/view_users.html', users=users)
|
||||
|
||||
|
||||
@user_bp.route('/handle_user_action', methods=['POST'])
|
||||
def handle_user_action():
|
||||
user_id = request.form['user_id']
|
||||
action = request.form['action']
|
||||
|
||||
if action == 'edit_user':
|
||||
return redirect(url_for('user_bp.edit_user', user_id=user_id))
|
||||
# Add more conditions for other actions
|
||||
return redirect(url_for('view_users'))
|
||||
|
||||
Reference in New Issue
Block a user