Compare commits
2 commits
2554900554
...
04ad554d3c
Author | SHA1 | Date | |
---|---|---|---|
04ad554d3c | |||
61544ed521 |
5 changed files with 329 additions and 369 deletions
673
poetry.lock
generated
673
poetry.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -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"
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -26,8 +26,9 @@ async def load(
|
|||
- MTGStand (uses Scryfall ID)
|
||||
"""
|
||||
async with await psycopg.AsyncConnection.connect(
|
||||
settings["database"], autocommit=False
|
||||
) as conn:
|
||||
settings["database"],
|
||||
autocommit=False,
|
||||
) as conn:
|
||||
async with conn.cursor() as cursor:
|
||||
if mode == ImportMode.replace:
|
||||
await tutor.database.clear_copies(cursor)
|
||||
|
@ -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:
|
||||
|
|
|
@ -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 = [
|
||||
(
|
||||
|
|
Loading…
Reference in a new issue