ndmhung6 commited on
Commit
b2ff24d
·
1 Parent(s): 37f58c5

fix: convert datetime to str in admin users list to fix JSON serializable error

Browse files
Files changed (1) hide show
  1. app.py +4 -1
app.py CHANGED
@@ -3047,7 +3047,10 @@ def admin_users_list():
3047
  cursor.execute("SELECT id, email, role, created_at FROM users ORDER BY id ASC")
3048
  user_list = cursor.fetchall()
3049
  for u in user_list:
3050
- cursor.execute("SELECT tool_path FROM user_permissions WHERE user_id = %d", (u['id'],))
 
 
 
3051
  u['permissions'] = [row['tool_path'] for row in cursor.fetchall()]
3052
  conn.close()
3053
  return render_template('tools/admin_users/index.html', users=user_list, available_tools=AVAILABLE_TOOLS)
 
3047
  cursor.execute("SELECT id, email, role, created_at FROM users ORDER BY id ASC")
3048
  user_list = cursor.fetchall()
3049
  for u in user_list:
3050
+ # Convert datetime to string so Jinja2 tojson can serialize it
3051
+ if u.get('created_at') and not isinstance(u['created_at'], str):
3052
+ u['created_at'] = str(u['created_at'])
3053
+ cursor.execute("SELECT tool_path FROM user_permissions WHERE user_id = %s", (u['id'],))
3054
  u['permissions'] = [row['tool_path'] for row in cursor.fetchall()]
3055
  conn.close()
3056
  return render_template('tools/admin_users/index.html', users=user_list, available_tools=AVAILABLE_TOOLS)