some changes to fix dropdown selection

This commit is contained in:
2025-03-28 16:41:13 -04:00
parent 2d0247d0d9
commit 728061c504
2 changed files with 24 additions and 20 deletions

View File

@@ -90,25 +90,35 @@ def sql():
@app.route('/user_list') @app.route('/user_list')
def user_list(): def user_list():
"""Displays the user list with VLAN IDs."""
db = get_db() db = get_db()
if db: if db is None:
return "Database connection failed", 500
cursor = db.cursor(dictionary=True) cursor = db.cursor(dictionary=True)
try:
# Fetch users and their group assignments
cursor.execute(""" cursor.execute("""
SELECT SELECT r.username AS mac_address, r.value AS description, ug.groupname AS vlan_id
rc.username AS mac_address, FROM radcheck r
IFNULL(rug.groupname, 'N/A') AS vlan_id, -- Changed to get groupname from radusergroup LEFT JOIN radusergroup ug ON r.username = ug.username
IFNULL((SELECT value FROM radcheck rch WHERE r.attribute = 'User-Description'
WHERE rch.username = rc.username AND rch.attribute = 'User-Description' LIMIT 1), 'N/A') AS description
FROM radcheck rc
LEFT JOIN radusergroup rug ON rc.username = rug.username -- Join radcheck and radusergroup
WHERE rc.attribute = 'Cleartext-Password'
GROUP BY rc.username;
""") """)
results = cursor.fetchall() results = cursor.fetchall()
# Fetch all group names for the dropdown
cursor.execute("SELECT groupname FROM radgroupcheck")
groups = cursor.fetchall()
groups = [{'groupname': row['groupname']} for row in groups] # changed
cursor.close() cursor.close()
db.close() db.close()
return render_template('user_list_inline_edit.html', results=results) return render_template('user_list_inline_edit.html', results=results, groups=groups) # added groups
return "Database Connection Failed" except mysql.connector.Error as e:
print(f"Database error: {e}")
cursor.close()
db.close()
return "Database error", 500
@app.route('/update_user', methods=['POST']) @app.route('/update_user', methods=['POST'])
def update_user(): def update_user():

View File

@@ -20,13 +20,7 @@
<td><input type="text" id="mac_address-{{ user.mac_address }}" value="{{ user.mac_address }}"></td> <td><input type="text" id="mac_address-{{ user.mac_address }}" value="{{ user.mac_address }}"></td>
<td><input type="text" id="description-{{ user.mac_address }}" value="{{ user.description }}"></td> <td><input type="text" id="description-{{ user.mac_address }}" value="{{ user.description }}"></td>
<td> <td>
<select id="vlan_id-{{ user.mac_address }}"> <input type="text" id="vlan_id-{{ user.mac_address }}" value="{{ user.vlan_id }}">
{% for group in groups %}
<option value="{{ group.groupname }}" {% if user.groupname == group.groupname %} selected {% endif %}>
{{ group.groupname }}
</option>
{% endfor %}
</select>
</td> </td>
<td> <td>
<button onclick="updateUser('{{ user.mac_address }}')"></button> <button onclick="updateUser('{{ user.mac_address }}')"></button>