| def list_users(ambiente,excel): |
| |
| from features.api_calls import clients |
| import pandas as pd |
| import tempfile |
|
|
| df = clients(ambiente) |
|
|
| if df.empty: |
| return (None, "⚠️ No se encontraron registros con esos filtros.") |
|
|
| if excel: |
| temp_file = tempfile.NamedTemporaryFile(delete=False, suffix=".xlsx") |
| df.to_excel(temp_file.name, index=False) |
| return (temp_file.name, "") |
| |
| |
| resumen = df[['_id','name']].head(10).to_string(index=False) |
| return (None, resumen) |
|
|
|
|
| def crear_usuario_excel(archivo_excel, ambiente): |
| |
| import pandas as pd |
| import json |
| from features.api_calls import create_user |
|
|
| if isinstance(archivo_excel, pd.DataFrame): |
| df = archivo_excel |
| else: |
| df = pd.read_excel(archivo_excel.name) |
|
|
| df.columns = df.columns.str.strip() |
|
|
| resultados = [] |
|
|
| for index, row in df.iterrows(): |
| username = str(row['username']).strip() |
| password = str(row['password']).strip() |
| email = str(row['email']).strip() if pd.notna(row['email']) else "" |
| firstName= str(row['firstName']).strip() |
| lastName= str(row['lastName']).strip() |
| role= str(row['role']).strip() |
| client= str(row['client']).strip() |
|
|
| json_query = { |
| "username": username, |
| 'password':password, |
| "email": email, |
| "firstName": firstName, |
| "lastName":lastName, |
| "role": role, |
| "client":client |
|
|
| } |
|
|
| try: |
| response = create_user(ambiente, json_query) |
| if response is not None: |
| resultados.append(f"✅ El cliente {username} fue creado (fila {index + 2}):\n{json.dumps(json_query, indent=2)}") |
| else: |
| resultados.append(f"❌ Error al crear cliente {username} (fila {index + 2})") |
| except Exception as e: |
| resultados.append(f"❌ Excepción en fila {index + 2}: {str(e)}") |
|
|
| return "\n\n".join(resultados) |
|
|