Edoruin commited on
Commit
0cfac32
·
1 Parent(s): c3e2362

eliminando elif

Browse files
Files changed (1) hide show
  1. app/main.py +83 -46
app/main.py CHANGED
@@ -1,25 +1,95 @@
1
- # --- PRÉSTAMOS ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  elif page.route == "/prestamos":
3
- # Cuadro de hora inicial recuperado
4
- ahora_dt = datetime.datetime.utcnow() - datetime.timedelta(hours=4)
5
- hora_rd = ahora_dt.strftime('%H:%M')
6
 
7
  nombre = ft.TextField(label="Alumno", expand=True)
8
  item = ft.TextField(label="Descripción del item", multiline=True, min_lines=2)
9
  cant = ft.TextField(label="Cant.", value="1", expand=1)
10
-
11
- # Campos de hora
12
- h_ext = ft.TextField(label="Hora Salida", value=hora_rd, expand=1)
13
- h_dev = ft.TextField(label="Devolución Est.", hint_text="HH:MM", expand=1)
14
-
15
  st_txt = ft.Text("", weight="bold")
16
- lista_historial = ft.ListView(expand=1, spacing=10, padding=10)
17
 
18
  def crear_card(d):
19
  return ft.Container(
20
  content=ft.ListTile(
21
  title=ft.Text(d['alumno'], weight="bold"),
22
- subtitle=ft.Text(f"{d['item']} (x{d['cantidad']})\n🕒 Salida: {d['hora']}"),
23
  trailing=ft.Icon(ft.Icons.CHECK_CIRCLE, color="green") if d['status']=="OK" else ft.Icon(ft.Icons.REPORT_GMAILERRORRED, color="orange"),
24
  on_click=lambda _: mostrar_factura(d)
25
  ),
@@ -33,41 +103,8 @@
33
  if not nombre.value or not item.value:
34
  st_txt.value = "⚠️ Completa los datos"; st_txt.color="red"; page.update(); return
35
 
36
- # Usamos el valor del cuadro de hora h_ext.value
37
  res = enviar_telegram(f"🛠 *PRÉSTAMO*\n👤 {nombre.value}\n📦 {item.value}\n🔢 Cant: {cant.value}\n🕒 Hora: {h_ext.value}")
38
-
39
- nuevo = {"alumno": nombre.value, "item": item.value, "cantidad": cant.value,
40
- "hora": h_ext.value, "devolucion": h_dev.value or "--:--", "status": res}
41
-
42
  historial_datos.append(nuevo)
43
  lista_historial.controls.insert(0, crear_card(nuevo))
44
- st_txt.value = "✅ Registrado" if res=="OK" else f"❌ Error: {res}"
45
- st_txt.color = "green" if res=="OK" else "orange"
46
- nombre.value = ""; item.value = ""; page.update()
47
-
48
- # Diseño adaptado para teléfonos (Column en lugar de Row si es necesario)
49
- page.views.append(
50
- ft.View("/prestamos", [
51
- ft.AppBar(title=ft.Text("Gestión de Préstamos"), bgcolor="#1a1c1e"),
52
- ft.Column([ # Cambiado a Column para mejor scroll en móvil
53
- ft.Text("NUEVO REGISTRO", size=18, weight="bold"),
54
- nombre,
55
- ft.Row([cant, h_ext, h_dev], spacing=10), # Fila de datos numéricos/hora
56
- item,
57
- ft.ElevatedButton(
58
- "CONFIRMAR PRÉSTAMO",
59
- icon=ft.Icons.SEND,
60
- on_click=registrar,
61
- bgcolor=ft.Colors.GREEN_800,
62
- color="white",
63
- style=ft.ButtonStyle(shape=ft.RoundedRectangleBorder(radius=8)),
64
- height=50
65
- ),
66
- st_txt,
67
- ft.Divider(),
68
- ft.Text("HISTORIAL RECIENTE (Click p/ detalle)", size=18, weight="bold"),
69
- lista_historial,
70
- ft.TextButton("Volver al Menú", on_click=lambda _: page.go("/"))
71
- ], scroll=ft.ScrollMode.ADAPTIVE, expand=True, spacing=15)
72
- ])
73
- )
 
1
+ import flet as ft
2
+ import gitlab
3
+ import os
4
+ import base64
5
+ import requests
6
+ import datetime
7
+
8
+ def main(page: ft.Page):
9
+ page.title = "MAKERSPACE DATABASE"
10
+ page.theme_mode = ft.ThemeMode.DARK
11
+ page.padding = 10 # Menos padding para aprovechar pantalla móvil
12
+
13
+ # --- CONFIGURACIÓN DE VARIABLES ---
14
+ TG_TOKEN = os.getenv("TELEGRAM_TOKEN")
15
+ TG_CHAT_ID = os.getenv("TELEGRAM_CHAT_ID")
16
+ GITLAB_URL = "https://gitlab.com"
17
+ GIT_TOKEN = os.getenv("GITLAB_TOKEN")
18
+ GIT_GROUP = os.getenv("GITLAB_GROUP_ID")
19
+
20
+ historial_datos = []
21
+
22
+ def enviar_telegram(mensaje):
23
+ if not TG_TOKEN or not TG_CHAT_ID: return "ERR_VAR"
24
+ token = str(TG_TOKEN).strip()
25
+ chat_id = str(TG_CHAT_ID).strip()
26
+ url = f"https://api.telegram.org/bot{token}/sendMessage"
27
+ payload = {"chat_id": chat_id, "text": mensaje, "parse_mode": "Markdown"}
28
+
29
+ for intento in range(3):
30
+ try:
31
+ response = requests.post(url, json=payload, timeout=12)
32
+ if response.status_code == 200:
33
+ return "OK"
34
+ else:
35
+ return f"API_{response.status_code}"
36
+ except requests.exceptions.RequestException:
37
+ continue
38
+ return "ERR_RED"
39
+
40
+ def mostrar_factura(i):
41
+ dialog = ft.AlertDialog(
42
+ title=ft.Text("RECIBO DE PRÉSTAMO", weight="bold"),
43
+ content=ft.Column([
44
+ ft.Text(f"ESTADO: {'✅ ENVIADO' if i['status']=='OK' else '⚠️ LOCAL'}",
45
+ color="green" if i['status']=='OK' else "orange", weight="bold"),
46
+ ft.Divider(),
47
+ ft.Text(f"ALUMNO: {i['alumno']}", size=16),
48
+ ft.Text(f"ITEM: {i['item']}", weight="bold"),
49
+ ft.Text(f"CANTIDAD: {i['cantidad']}"),
50
+ ft.Divider(),
51
+ ft.Text(f"SALIDA: {i['hora']}"),
52
+ ft.Text(f"RETORNO EST.: {i['devolucion']}"),
53
+ ], tight=True, spacing=5),
54
+ actions=[ft.TextButton("Cerrar", on_click=lambda _: page.close_dialog())]
55
+ )
56
+ page.dialog = dialog
57
+ dialog.open = True
58
+ page.update()
59
+
60
+ def route_change(route):
61
+ page.views.clear()
62
+
63
+ # --- MENÚ PRINCIPAL ---
64
+ if page.route == "/":
65
+ page.views.append(
66
+ ft.View("/", [
67
+ ft.AppBar(title=ft.Text("MAKERSPACE"), bgcolor="#1a1c1e"),
68
+ ft.Column([
69
+ ft.Text("PANEL DE CONTROL", size=24, weight="bold"),
70
+ ft.ElevatedButton("GITLAB REPOS", icon=ft.Icons.FOLDER, on_click=lambda _: page.go("/repos"), height=80, width=float("inf")),
71
+ ft.ElevatedButton("SISTEMA PRÉSTAMOS", icon=ft.Icons.BUILD, on_click=lambda _: page.go("/prestamos"), height=80, width=float("inf"), bgcolor=ft.Colors.BLUE_800),
72
+ ], spacing=20, horizontal_alignment=ft.CrossAxisAlignment.CENTER)
73
+ ])
74
+ )
75
+
76
+ # --- SECCIÓN PRÉSTAMOS (DISEÑO MÓVIL + HORA) ---
77
  elif page.route == "/prestamos":
78
+ ahora_rd = (datetime.datetime.utcnow() - datetime.timedelta(hours=4)).strftime('%H:%M')
 
 
79
 
80
  nombre = ft.TextField(label="Alumno", expand=True)
81
  item = ft.TextField(label="Descripción del item", multiline=True, min_lines=2)
82
  cant = ft.TextField(label="Cant.", value="1", expand=1)
83
+ h_ext = ft.TextField(label="Hora Salida", value=ahora_rd, expand=1)
84
+ h_dev = ft.TextField(label="Devolución", hint_text="HH:MM", expand=1)
 
 
 
85
  st_txt = ft.Text("", weight="bold")
86
+ lista_historial = ft.ListView(expand=True, spacing=10)
87
 
88
  def crear_card(d):
89
  return ft.Container(
90
  content=ft.ListTile(
91
  title=ft.Text(d['alumno'], weight="bold"),
92
+ subtitle=ft.Text(f"{d['item']} (x{d['cantidad']})"),
93
  trailing=ft.Icon(ft.Icons.CHECK_CIRCLE, color="green") if d['status']=="OK" else ft.Icon(ft.Icons.REPORT_GMAILERRORRED, color="orange"),
94
  on_click=lambda _: mostrar_factura(d)
95
  ),
 
103
  if not nombre.value or not item.value:
104
  st_txt.value = "⚠️ Completa los datos"; st_txt.color="red"; page.update(); return
105
 
 
106
  res = enviar_telegram(f"🛠 *PRÉSTAMO*\n👤 {nombre.value}\n📦 {item.value}\n🔢 Cant: {cant.value}\n🕒 Hora: {h_ext.value}")
107
+ nuevo = {"alumno": nombre.value, "item": item.value, "cantidad": cant.value, "hora": h_ext.value, "devolucion": h_dev.value or "--:--", "status": res}
 
 
 
108
  historial_datos.append(nuevo)
109
  lista_historial.controls.insert(0, crear_card(nuevo))
110
+ st_txt.value = "✅ Registrado" if res=="OK" else