61 lines
2.0 KiB
Python
61 lines
2.0 KiB
Python
"""queries/api_iscrizioni.py — rpa_intra_api_iscrizione (Intraz)"""
|
|
|
|
from .db import query, count, e, dt
|
|
|
|
|
|
def get_iscrizioni(db_path: str) -> list:
|
|
return query(db_path, """
|
|
SELECT
|
|
i.id,
|
|
i.rpa_process_id,
|
|
m.ragione_sociale AS sorgente,
|
|
i.sessione_id,
|
|
i.iscritto_nome,
|
|
i.iscritto_cognome,
|
|
i.iscritto_azienda,
|
|
i.iscritto_cf,
|
|
i.odv_numero,
|
|
i.persona_inserita_only1,
|
|
i.created_at,
|
|
i.updated_at
|
|
FROM rpa_intra_api_iscrizione i
|
|
LEFT JOIN rpa_mapping_aziende m ON m.id = i.azienda_sorgente_id
|
|
WHERE date(i.created_at) >= date('now', '-10 days')
|
|
ORDER BY i.id DESC
|
|
LIMIT 500
|
|
""")
|
|
|
|
|
|
def get_stats(db_path: str) -> dict:
|
|
return {
|
|
'api_isc_total': count(db_path, "SELECT COUNT(*) AS n FROM rpa_intra_api_iscrizione"),
|
|
}
|
|
|
|
|
|
def render_table(rows: list) -> str:
|
|
if not rows:
|
|
return '<p class="empty">Nessuna iscrizione trovata.</p>'
|
|
|
|
trs = ''.join(
|
|
f'<tr data-date="{e((r.get("created_at") or "")[:10])}">'
|
|
f'<td>{e(r.get("id"))}</td>'
|
|
f'<td>{e(r.get("rpa_process_id"))}</td>'
|
|
f'<td>{e(r.get("sorgente"))}</td>'
|
|
f'<td>{e(r.get("sessione_id"))}</td>'
|
|
f'<td>{e(r.get("iscritto_cognome"))} {e(r.get("iscritto_nome"))}</td>'
|
|
f'<td>{e(r.get("iscritto_azienda"))}</td>'
|
|
f'<td>{e(r.get("iscritto_cf"))}</td>'
|
|
f'<td>{e(r.get("odv_numero"))}</td>'
|
|
f'<td>{"✓" if r.get("persona_inserita_only1") else ""}</td>'
|
|
f'<td>{dt(r.get("updated_at"))}</td>'
|
|
f'</tr>'
|
|
for r in rows
|
|
)
|
|
return (
|
|
'<table><thead><tr>'
|
|
'<th>#</th><th>Run</th><th>Sorgente</th><th>Sessione</th>'
|
|
'<th>Iscritto</th><th>Azienda</th><th>CF</th><th>ODV N.</th>'
|
|
'<th>New utente Only1</th><th>Aggiornato</th>'
|
|
f'</tr></thead><tbody>{trs}</tbody></table>'
|
|
)
|