From 8c2ab10eb16701668e9a506f51ee589ceb9bd93b Mon Sep 17 00:00:00 2001 From: mily Date: Fri, 18 Apr 2025 22:55:17 +0200 Subject: [PATCH 1/3] Home: create bar with full name and class --- src/pages/home.py | 32 ++++++++++++++++++++++++++++---- src/utils.py | 6 +++++- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/src/pages/home.py b/src/pages/home.py index ef9939f..5139245 100644 --- a/src/pages/home.py +++ b/src/pages/home.py @@ -1,15 +1,39 @@ import flet as ft +import configparser from i18n import _ from constants import * -from homeutils import RecentGradesColumn # Import the function from your new file +from homeutils import RecentGradesColumn +from utils import getconfigpath, getinitials def HomePage(): + config = configparser.ConfigParser() + config.read(f"{getconfigpath()}/config.ini") + + studentFullName = config['User']['fullName'] + studentClass = config['User']['grade'] return ft.Column([ ft.Text((_("Home")), size=30, weight="bold"), ft.Text("\n", size=30, weight="bold"), + ft.Card( + content=ft.Container( + content=ft.Column( + controls=[ + ft.ListTile( + leading=ft.CircleAvatar( + content=ft.Text(getinitials(studentFullName)), + ), + title=ft.Text(studentFullName), + subtitle=ft.Text(studentClass), + ), + ] + ), + width=400, + padding=10 + ), + ), ft.Row([ ft.Card( - content=ft.Container( # Timetable Card + content=ft.Container( content=ft.Column([ ft.Row([ ft.Icon(ft.Icons.BACKPACK_OUTLINED, size=32, color="#FFFFFF"), @@ -34,8 +58,8 @@ def HomePage(): ), ft.Card( - content=ft.Container( # Recent Grades Card - content=RecentGradesColumn(), # Use the imported function here + content=ft.Container( + content=RecentGradesColumn(), #margin=20, padding=10, alignment=ft.alignment.top_left, diff --git a/src/utils.py b/src/utils.py index 8155825..0d3e34e 100644 --- a/src/utils.py +++ b/src/utils.py @@ -102,4 +102,8 @@ def get_current_month_dates(): next_month = today.replace(month=today.month + 1, day=1) end_date = next_month - timedelta(days=1) - return start_date.strftime("%Y-%m-%d"), end_date.strftime("%Y-%m-%d") \ No newline at end of file + return start_date.strftime("%Y-%m-%d"), end_date.strftime("%Y-%m-%d") + +def getinitials(full_name): + initials = ''.join([part[0].upper() for part in full_name.split()]) + return initials \ No newline at end of file From 1866f61b05baf74414c8280fbb41cf23a3912043 Mon Sep 17 00:00:00 2001 From: mily Date: Fri, 18 Apr 2025 23:42:34 +0200 Subject: [PATCH 2/3] Add logging out --- src/pages/settings.py | 23 +++++++++++++++++++++-- src/utils.py | 16 +++++++++++++++- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/src/pages/settings.py b/src/pages/settings.py index 7b5531a..1021952 100644 --- a/src/pages/settings.py +++ b/src/pages/settings.py @@ -1,13 +1,26 @@ import flet as ft from constants import * -from utils import setthemecolor, setlanguage, restart +from utils import setthemecolor, setlanguage, restart, logout from i18n import _, set_language def SettingsPage(page): # Create the main container to hold everything main_container = ft.Container() + + def handle_logout(e): + logout() + restart(e.page) + logout_modal = ft.AlertDialog( + modal=True, + title=ft.Text(_("Logout")), + content=ft.Text(_("Do you want to logout?")), + actions=[ + ft.TextButton("Yes", on_click=handle_logout), + ft.TextButton("No", on_click=lambda e: page.close(logout_modal)), + ], + actions_alignment=ft.MainAxisAlignment.END, + ) - # Create a custom notification that we'll show/hide notification = ft.Container( visible=False, bgcolor=ft.colors.AMBER_100, @@ -103,6 +116,12 @@ def SettingsPage(page): on_change=onthemechange ) ]), + ft.Row([ + ft.ElevatedButton( + _("Logout"), + on_click=lambda e: page.open(logout_modal) + ), + ]), ]), expand=True # Make this container expand to push the notification to the bottom ), diff --git a/src/utils.py b/src/utils.py index 0d3e34e..57b07a8 100644 --- a/src/utils.py +++ b/src/utils.py @@ -106,4 +106,18 @@ def get_current_month_dates(): def getinitials(full_name): initials = ''.join([part[0].upper() for part in full_name.split()]) - return initials \ No newline at end of file + return initials + +def logout(): + config = configparser.ConfigParser() + config.read(f"{getconfigpath()}/config.ini") + config["Settings"]["islogged"] = "False" + config["User"]["fullname"] = "" + config["User"]["grade"] = "" + config["User"]["semester"] = "1" + + if os.path.exists("database.db"): + os.remove("database.db") + + with open(f"{getconfigpath()}/config.ini", "w") as file: + config.write(file) \ No newline at end of file From daa2126756a47ec7c89fa7317549bc7fd23c6742 Mon Sep 17 00:00:00 2001 From: mily Date: Fri, 18 Apr 2025 23:44:34 +0200 Subject: [PATCH 3/3] Fix timetable error when Room is null --- src/sdk/src/models/lesson.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sdk/src/models/lesson.py b/src/sdk/src/models/lesson.py index e47dac4..df24fa5 100644 --- a/src/sdk/src/models/lesson.py +++ b/src/sdk/src/models/lesson.py @@ -32,7 +32,7 @@ class Lesson(BaseModel): return Lesson( position = data["TimeSlot"]["Position"], date = datetime.fromtimestamp(data["Date"]["Timestamp"] / 1000).date(), - room = data["Room"]["Code"], + room = data["Room"]["Code"] if data.get("Room") else None, start = datetime.strptime(data["TimeSlot"]["Start"], "%H:%M").time(), end = datetime.strptime(data["TimeSlot"]["End"], "%H:%M").time(), subject = data["Subject"]["Name"] if data["Subject"] else data["Event"],