|
import streamlit as st |
|
import datetime |
|
import pronotepy |
|
import uuid |
|
|
|
def app(client): |
|
st.title('📚 Devoirs') |
|
|
|
|
|
selected_week = st.date_input("Sélectionnez une semaine", value=datetime.date.today()) |
|
start_week = selected_week - datetime.timedelta(days=selected_week.weekday()) |
|
end_week = start_week + datetime.timedelta(days=4) |
|
|
|
|
|
homeworks = client.homework(start_week, end_week) |
|
|
|
|
|
tabs = st.tabs(["🔴 À faire durant la semaine", "1️⃣ Lundi", "2️⃣ Mardi", "3️⃣ Mercredi", "4️⃣ Jeudi", "5️⃣ Vendredi", "🟢 Déjà fait durant la semaine"]) |
|
days = [start_week + datetime.timedelta(days=i) for i in range(5)] |
|
|
|
with tabs[0]: |
|
homeworks_to_do = [hw for hw in homeworks if not hw.done] |
|
display_homework_list(homeworks_to_do, client) |
|
|
|
with tabs[6]: |
|
homeworks_done = [hw for hw in homeworks if hw.done] |
|
display_homework_list(homeworks_done, client) |
|
|
|
for i, tab in enumerate(tabs[1:5]): |
|
with tab: |
|
daily_homeworks = [hw for hw in homeworks if hw.date == days[i]] |
|
display_homework_list(daily_homeworks, client) |
|
|
|
def display_homework_list(homeworks, client): |
|
for homework in homeworks: |
|
with st.expander(f"{"✅" if homework.done else "❌"} | {homework.subject.name} - *pour le {homework.date.strftime('%d/%m/%Y')}*"): |
|
st.markdown(f""" |
|
- **Statut :** {"✅ Fait" if homework.done else "❌ À faire"} |
|
- **Description :** {homework.description} |
|
""", unsafe_allow_html=True) |
|
|
|
|
|
unique_key = str(uuid.uuid4()) |
|
|
|
|
|
st.button("✅ Marquer comme fait" if not homework.done else "❌ Marquer comme à faire", key=unique_key, on_click=update_homework_status, args=(homework, client)) |
|
|
|
def update_homework_status(homework, client): |
|
new_status = not homework.done |
|
homework.set_done(new_status) |