Courrier v1.6 (tt-2026-11-069) : Courses pour Tunis, liste a cocher, ajout depuis la lecture, export Excel
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01XGaEeWkqZYNP6Wn3mGQsrL
This commit is contained in:
1 parent
ce10cae840
commit
b712ee10cd
8 files changed
+471
-11
No files matched your search
@@ -410,3 +410,96 @@ def set_traite(message_id: str, traite: bool, db_path: Optional[str] = None) ->
|
||||
return get_classement(message_id, db_path)
|
||||
finally:
|
||||
conn.close()
|
||||
|
||||
|
||||
# --- Courses pour Tunis ---
|
||||
SENS_COURSE = ("tunis_sfax", "sfax_tunis")
|
||||
|
||||
|
||||
def _courses_pret(conn: sqlite3.Connection) -> None:
|
||||
conn.execute("""
|
||||
CREATE TABLE IF NOT EXISTS courses (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
message_id TEXT,
|
||||
demande TEXT NOT NULL,
|
||||
sens TEXT NOT NULL DEFAULT 'tunis_sfax',
|
||||
objet_mail TEXT,
|
||||
expediteur TEXT,
|
||||
date_mail TEXT,
|
||||
statut TEXT NOT NULL DEFAULT 'a_faire',
|
||||
cree_le TEXT NOT NULL,
|
||||
fait_le TEXT
|
||||
)""")
|
||||
|
||||
|
||||
def list_courses(statut: Optional[str] = None, db_path: Optional[str] = None) -> List[Dict[str, Any]]:
|
||||
conn = get_connection(db_path)
|
||||
try:
|
||||
_courses_pret(conn)
|
||||
if statut in ("a_faire", "faite"):
|
||||
rows = conn.execute("SELECT * FROM courses WHERE statut = ? ORDER BY cree_le DESC, id DESC", (statut,)).fetchall()
|
||||
else:
|
||||
rows = conn.execute("SELECT * FROM courses ORDER BY (statut = 'faite'), cree_le DESC, id DESC").fetchall()
|
||||
return [dict(r) for r in rows]
|
||||
finally:
|
||||
conn.close()
|
||||
|
||||
|
||||
def get_course(course_id: int, db_path: Optional[str] = None) -> Optional[Dict[str, Any]]:
|
||||
conn = get_connection(db_path)
|
||||
try:
|
||||
_courses_pret(conn)
|
||||
r = conn.execute("SELECT * FROM courses WHERE id = ?", (course_id,)).fetchone()
|
||||
return dict(r) if r else None
|
||||
finally:
|
||||
conn.close()
|
||||
|
||||
|
||||
def add_course(demande: str, sens: str = "tunis_sfax", message_id: Optional[str] = None, objet_mail: Optional[str] = None,
|
||||
expediteur: Optional[str] = None, date_mail: Optional[str] = None, db_path: Optional[str] = None) -> Dict[str, Any]:
|
||||
conn = get_connection(db_path)
|
||||
try:
|
||||
_courses_pret(conn)
|
||||
with conn:
|
||||
cur = conn.execute(
|
||||
"INSERT INTO courses (message_id, demande, sens, objet_mail, expediteur, date_mail, cree_le) VALUES (?, ?, ?, ?, ?, ?, ?)",
|
||||
(message_id, demande, sens, objet_mail, expediteur, date_mail, get_tunis_now_iso()))
|
||||
new_id = cur.lastrowid
|
||||
r = conn.execute("SELECT * FROM courses WHERE id = ?", (new_id,)).fetchone()
|
||||
return dict(r)
|
||||
finally:
|
||||
conn.close()
|
||||
|
||||
|
||||
def update_course(course_id: int, demande: Optional[str] = None, sens: Optional[str] = None, statut: Optional[str] = None,
|
||||
db_path: Optional[str] = None) -> Optional[Dict[str, Any]]:
|
||||
conn = get_connection(db_path)
|
||||
try:
|
||||
_courses_pret(conn)
|
||||
actuel = conn.execute("SELECT * FROM courses WHERE id = ?", (course_id,)).fetchone()
|
||||
if not actuel:
|
||||
return None
|
||||
champs, vals = [], []
|
||||
if demande is not None:
|
||||
champs.append("demande = ?"); vals.append(demande)
|
||||
if sens is not None:
|
||||
champs.append("sens = ?"); vals.append(sens)
|
||||
if statut is not None and statut != actuel["statut"]:
|
||||
champs.append("statut = ?"); vals.append(statut)
|
||||
champs.append("fait_le = ?"); vals.append(get_tunis_now_iso() if statut == "faite" else None)
|
||||
if champs:
|
||||
with conn:
|
||||
conn.execute("UPDATE courses SET " + ", ".join(champs) + " WHERE id = ?", (*vals, course_id))
|
||||
return dict(conn.execute("SELECT * FROM courses WHERE id = ?", (course_id,)).fetchone())
|
||||
finally:
|
||||
conn.close()
|
||||
|
||||
|
||||
def delete_course(course_id: int, db_path: Optional[str] = None) -> bool:
|
||||
conn = get_connection(db_path)
|
||||
try:
|
||||
_courses_pret(conn)
|
||||
with conn:
|
||||
return conn.execute("DELETE FROM courses WHERE id = ?", (course_id,)).rowcount > 0
|
||||
finally:
|
||||
conn.close()
|
||||
Reference in new issue
Block a user