gadasin/UI/src/requests/board_games.py

35 lines
881 B
Python

import psycopg2
from models.game import Game
from requests.connection import get_cursor
def get_sections():
cursor = get_cursor()
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