feat: UI games listing
This commit is contained in:
parent
49c6b54617
commit
b47278beb6
|
@ -1,23 +1,90 @@
|
|||
import flet as ft
|
||||
|
||||
from requests.board_games import get_sections
|
||||
|
||||
from requests.board_games import get_sections, get_games
|
||||
|
||||
def main(page: ft.Page):
|
||||
def update_games(section):
|
||||
current_section.value = section
|
||||
games = get_games(None if section == "Все" else section)
|
||||
grid.controls.clear()
|
||||
for game in games:
|
||||
grid.controls.append(
|
||||
ft.Column([
|
||||
ft.Text(str(game)),
|
||||
ft.Row([
|
||||
ft.IconButton(icon=ft.icons.SHOPPING_CART),
|
||||
ft.IconButton(icon=ft.icons.FAVORITE),
|
||||
]),
|
||||
])
|
||||
)
|
||||
page.update()
|
||||
|
||||
print("Rerender!")
|
||||
page.title = "Весёлые кубики"
|
||||
|
||||
sections = get_sections()
|
||||
sections = [*get_sections(), "Все"]
|
||||
|
||||
sections_buttons = [ft.Button(section) for section in sections]
|
||||
sections_buttons = [ft.Button(section, on_click=lambda e, s=section: update_games(s)) for section in sections]
|
||||
|
||||
games = get_games()
|
||||
|
||||
current_section = ft.Ref[str]()
|
||||
|
||||
grid = ft.GridView(
|
||||
expand=1,
|
||||
runs_count=5,
|
||||
max_extent=200,
|
||||
child_aspect_ratio=1.0,
|
||||
spacing=5,
|
||||
run_spacing=5,
|
||||
)
|
||||
|
||||
for game in games:
|
||||
grid.controls.append(
|
||||
ft.Column([
|
||||
ft.Text(str(game)),
|
||||
ft.Row([
|
||||
ft.IconButton(
|
||||
icon=ft.Icons.SHOPPING_CART
|
||||
),
|
||||
ft.IconButton(
|
||||
icon=ft.Icons.FAVORITE
|
||||
)
|
||||
])
|
||||
])
|
||||
)
|
||||
|
||||
page.add(
|
||||
ft.SafeArea(
|
||||
ft.Row(
|
||||
[
|
||||
ft.Text(
|
||||
"Весёлые кубики",
|
||||
color="#59799f",
|
||||
size=24,
|
||||
weight=ft.FontWeight.BOLD,
|
||||
),
|
||||
ft.Row([
|
||||
ft.Button(
|
||||
text="Вход",
|
||||
on_click=lambda e: print("Button 1 clicked"),
|
||||
),
|
||||
ft.Button(
|
||||
text="Регистрация",
|
||||
on_click=lambda e: print("Button 2 clicked"),
|
||||
),
|
||||
])
|
||||
],
|
||||
alignment=ft.MainAxisAlignment.SPACE_BETWEEN, # Adjust alignment if needed
|
||||
),
|
||||
ft.Column (
|
||||
[ft.Row(sections_buttons, alignment=ft.MainAxisAlignment.CENTER)],
|
||||
alignment=ft.MainAxisAlignment.START
|
||||
)
|
||||
)
|
||||
),
|
||||
grid
|
||||
)
|
||||
|
||||
|
||||
ft.app(main)
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
class Game:
|
||||
def __init__(self, board_game_id, name, genre, publisher, price):
|
||||
self.board_game_id = board_game_id
|
||||
self.name = name
|
||||
self.genre = genre
|
||||
self.publisher = publisher
|
||||
self.price = price
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.name}\nЖанр: {self.genre}\nИздатель: {self.publisher}\n{self.price}"
|
|
@ -1,3 +1,6 @@
|
|||
import psycopg2
|
||||
|
||||
from models.game import Game
|
||||
from requests.connection import get_cursor
|
||||
|
||||
|
||||
|
@ -7,3 +10,25 @@ def get_sections():
|
|||
cursor.execute("select name from sections")
|
||||
|
||||
return [elem[0] for elem in cursor.fetchall()]
|
||||
|
||||
|
||||
def get_games(section = None):
|
||||
cursor = get_cursor()
|
||||
|
||||
cursor.execute("SET lc_monetary TO 'ru_RU.UTF-8'")
|
||||
|
||||
if section is None:
|
||||
cursor.execute("""
|
||||
select *
|
||||
from board_games join sections_board_games using(board_game_id) join sections using(section_id)
|
||||
""")
|
||||
else:
|
||||
cursor.execute(f"""
|
||||
select *
|
||||
from board_games join sections_board_games using(board_game_id) join sections using(section_id)
|
||||
where sections.name='{section}'
|
||||
""")
|
||||
|
||||
res = [Game(game[1], game[2], game[3], game[4], game[5]) for game in cursor.fetchall()]
|
||||
|
||||
return res
|
||||
|
|
|
@ -105,8 +105,8 @@ INSERT INTO bags_board_games (bag_id, board_game_id, count) VALUES
|
|||
|
||||
INSERT INTO wishlists (client_id) VALUES
|
||||
(1),
|
||||
(1),
|
||||
(1),
|
||||
(2),
|
||||
(3),
|
||||
(4),
|
||||
(5),
|
||||
(6),
|
||||
|
|
Loading…
Reference in New Issue