Compare commits

...

2 commits

Author SHA1 Message Date
04ad554d3c Fix type errors 2024-02-21 17:38:20 -05:00
61544ed521 Fix schema loading
Remove usage of deprecated importlib.resources.path
2024-02-21 17:26:20 -05:00
5 changed files with 329 additions and 369 deletions

673
poetry.lock generated

File diff suppressed because it is too large Load diff

View file

@ -7,7 +7,7 @@ authors = ["Correl Roush <correl@gmail.com>"]
[tool.poetry.dependencies]
python = "^3.9"
tornado = "^6.1"
click = "^8.0.1"
click = "^8.1.7"
humanize = "^3.10.0"
httpx = "^0.18.2"
parsy = "^1.3.0"

View file

@ -7,10 +7,11 @@ import tornado.template
import tornado_openapi3.testing
import yaml
import tutor
import tutor.database
import tutor.server
template_path = importlib.resources.path("tutor", "templates")
template_path = importlib.resources.files(tutor) / "templates"
template_loader = tornado.template.Loader(str(template_path))
openapi_spec_dict = yaml.safe_load(
template_loader.load("openapi.yaml").generate(

View file

@ -26,7 +26,8 @@ async def load(
- MTGStand (uses Scryfall ID)
"""
async with await psycopg.AsyncConnection.connect(
settings["database"], autocommit=False
settings["database"],
autocommit=False,
) as conn:
async with conn.cursor() as cursor:
if mode == ImportMode.replace:
@ -36,7 +37,9 @@ async def load(
is_foil = "Foil" in row and row["Foil"].lower() == "foil"
quantity = int(row.get("Quantity", row.get("Count", 1)))
if "Creation Date" in row:
created_date = arrow.get(row["Creation Date"].replace('_', ' '))
created_date = arrow.get(
row["Creation Date"].replace("_", " ")
).datetime
else:
created_date = datetime.datetime.now()
if "Scryfall ID" in row:

View file

@ -302,6 +302,9 @@ class DecksHandler(OpenAPIRequestHandler, RequestHandler):
async with self.pool.connection() as conn:
async with conn.cursor() as cursor:
deck_id = await tutor.database.store_deck(cursor, name)
if not deck_id:
logger.error("Failed to store new deck")
raise tornado.web.HTTPError(500)
deck = tutor.models.Deck(deck_id, name, [])
self.write(json.dumps(deck, cls=JSONEncoder))
@ -310,7 +313,7 @@ class DecksHandler(OpenAPIRequestHandler, RequestHandler):
class DeckHandler(RequestHandler):
async def prepare(self) -> None:
self.connection = await self.pool.getconn()
self.deck_id = self.path_args[0]
self.deck_id = int(self.path_args[0])
content_type = self.request.headers.get("Content-Type", "text/plain")
if content_type == "text/plain":
self.importer = DeckImporter()
@ -416,8 +419,10 @@ class StaticFileHandler(tornado.web.StaticFileHandler):
class Application(tornado.web.Application):
def __init__(self, **settings):
version = importlib.metadata.version(__package__)
with importlib.resources.path(__package__, "templates") as template_path:
settings.setdefault("template_path", template_path)
settings.setdefault(
"template_path",
importlib.resources.files(__package__) / "templates",
)
paths = [
(