fix: UI discounts

This commit is contained in:
DEsimas 2024-12-20 01:14:18 +03:00
parent 562767a60d
commit b0aba2366d
3 changed files with 13 additions and 6 deletions

View File

@ -160,3 +160,4 @@ def main(page: ft.Page):
ft.app(main) ft.app(main)

View File

@ -15,4 +15,4 @@ class Game:
def __str__(self): def __str__(self):
cleaned_string = self.price.replace("\u202f", "")[:-2] cleaned_string = self.price.replace("\u202f", "")[:-2]
cleaned_string = cleaned_string.replace(",", ".") 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 "")

View File

@ -3,11 +3,22 @@ from requests.board_games import get_sections, get_games, get_user_discounts
def root(page: ft.Page): 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): def update_games(section):
current_section.value = section current_section.value = section
games = get_games(None if section == "Все" else section) games = get_games(None if section == "Все" else section)
grid.controls.clear() grid.controls.clear()
for game in games: for game in games:
for d in discounts:
if d.game_id == game.board_game_id:
game.discount = d.discount
grid.controls.append( grid.controls.append(
ft.Column([ ft.Column([
ft.Text(str(game)), ft.Text(str(game)),
@ -27,12 +38,7 @@ def root(page: ft.Page):
current_section = ft.Ref[str]() 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( grid = ft.GridView(
expand=1, expand=1,