fix: UI discounts
This commit is contained in:
parent
562767a60d
commit
b0aba2366d
|
@ -160,3 +160,4 @@ def main(page: ft.Page):
|
|||
|
||||
|
||||
ft.app(main)
|
||||
|
||||
|
|
|
@ -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 "")
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue