From b0aba2366dc3c0b9d2ee5df4f716414af5b30791 Mon Sep 17 00:00:00 2001 From: DEsimas Date: Fri, 20 Dec 2024 01:14:18 +0300 Subject: [PATCH] fix: UI discounts --- UI/src/main.py | 1 + UI/src/models/game.py | 2 +- UI/src/pages/root.py | 16 +++++++++++----- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/UI/src/main.py b/UI/src/main.py index 565b9a9..6772871 100644 --- a/UI/src/main.py +++ b/UI/src/main.py @@ -160,3 +160,4 @@ def main(page: ft.Page): ft.app(main) + diff --git a/UI/src/models/game.py b/UI/src/models/game.py index 458ce71..1d77dd2 100644 --- a/UI/src/models/game.py +++ b/UI/src/models/game.py @@ -15,4 +15,4 @@ class Game: def __str__(self): cleaned_string = self.price.replace("\u202f", "")[:-2] cleaned_string = cleaned_string.replace(",", ".") - return f"{self.name}\nЖанр: {self.genre}\nИздатель: {self.publisher}\n" + (str(self.price) if self.discount is None else f"{math.ceil(float(cleaned_string) * self.discount / 100)} ₽ -{self.discount}%") + (f"\n{self.count} шт." if self.count is not None else "") + return f"{self.name}\nЖанр: {self.genre}\nИздатель: {self.publisher}\n" + (str(self.price) if self.discount is None else f"{math.ceil(float(cleaned_string) * (100 - self.discount) / 100)} ₽ -{self.discount}%") + (f"\n{self.count} шт." if self.count is not None else "") diff --git a/UI/src/pages/root.py b/UI/src/pages/root.py index 4393886..97a80f1 100644 --- a/UI/src/pages/root.py +++ b/UI/src/pages/root.py @@ -3,11 +3,22 @@ from requests.board_games import get_sections, get_games, get_user_discounts def root(page: ft.Page): + user_id = page.client_storage.get("user_id"); + + discounts = [] + + if user_id is not None: + discounts = get_user_discounts(user_id) + def update_games(section): current_section.value = section games = get_games(None if section == "Все" else section) grid.controls.clear() for game in games: + for d in discounts: + if d.game_id == game.board_game_id: + game.discount = d.discount + grid.controls.append( ft.Column([ ft.Text(str(game)), @@ -27,12 +38,7 @@ def root(page: ft.Page): current_section = ft.Ref[str]() - user_id = page.client_storage.get("user_id"); - discounts = [] - - if user_id is not None: - discounts = get_user_discounts(user_id) grid = ft.GridView( expand=1,