From 68cfd0e7f6f05b186f1853a666d58b92cb92b66e Mon Sep 17 00:00:00 2001 From: evilchili Date: Thu, 30 Oct 2025 20:52:15 -0700 Subject: [PATCH] formatting --- src/ttfrog/app.py | 3 +-- src/ttfrog/bootstrap.py | 1 + src/ttfrog/forms.py | 2 +- src/ttfrog/schema.py | 16 +++++++++++----- src/ttfrog/web.py | 11 +++++------ 5 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/ttfrog/app.py b/src/ttfrog/app.py index 47d2fda..63a5caa 100644 --- a/src/ttfrog/app.py +++ b/src/ttfrog/app.py @@ -159,7 +159,7 @@ API_URI=/_/v1/ if "/" in uri: (parent_uri, page_name) = uri.rsplit("/", 1) - if parent_uri == 'Page': + if parent_uri == "Page": parent_uri = None search_uri = page_name else: @@ -169,7 +169,6 @@ API_URI=/_/v1/ # self.log.debug("\n".join([f"{p.doc_id}: {p.uri}" for p in table.all()])) page = table.get(where("uri") == search_uri, recurse=False) if not page: - # load the parent to check for write permissions # self.log.debug(f"Page at {search_uri} does not exist, looking for parent at {parent_uri=}") parent_table = table if parent_uri and "/" in parent_uri else self.db.Page diff --git a/src/ttfrog/bootstrap.py b/src/ttfrog/bootstrap.py index c18470a..792d459 100644 --- a/src/ttfrog/bootstrap.py +++ b/src/ttfrog/bootstrap.py @@ -56,6 +56,7 @@ def bootstrap(): # create the users guest = users.add_member(schema.User(name="guest", body=b"# guest")) + admin = users.add_member( schema.User(name=app.config.ADMIN_USERNAME, password="fnord", email=app.config.ADMIN_EMAIL, body=b"# fnord") ) diff --git a/src/ttfrog/forms.py b/src/ttfrog/forms.py index 4d91563..2d32047 100644 --- a/src/ttfrog/forms.py +++ b/src/ttfrog/forms.py @@ -1,6 +1,6 @@ +import logging from dataclasses import dataclass, field from functools import cached_property -import logging from flask import g from grung.types import BackReference, Collection, Pointer, Record, Timestamp diff --git a/src/ttfrog/schema.py b/src/ttfrog/schema.py index 93109e0..9e67ce7 100644 --- a/src/ttfrog/schema.py +++ b/src/ttfrog/schema.py @@ -2,8 +2,8 @@ from __future__ import annotations from datetime import datetime from enum import StrEnum -from typing import List from textwrap import dedent +from typing import List from grung.types import ( BackReference, @@ -37,7 +37,9 @@ class Page(Record): """ A page in the wiki. Just about everything in the databse is either a Page or a subclass of a Page. """ - default = dedent(""" + + default = dedent( + """ # {name} *Overview of this page* @@ -47,7 +49,8 @@ class Page(Record): *Organize your text into logically separted sections.* - """) + """ + ) @classmethod def fields(cls): @@ -222,7 +225,9 @@ class NPC(Page): """ An NPC, editable as a wiki page. """ - default = dedent(""" + + default = dedent( + """ # {name} *[Ancestry] [Class]* @@ -236,4 +241,5 @@ class NPC(Page): * Flaw: **[flaw]** * Goal: **[goal]** -""") +""" + ) diff --git a/src/ttfrog/web.py b/src/ttfrog/web.py index e01592a..54a1061 100644 --- a/src/ttfrog/web.py +++ b/src/ttfrog/web.py @@ -1,11 +1,11 @@ import json +import re from flask import Response, g, jsonify, redirect, render_template, request, session, url_for +from tinydb import where from ttfrog import app, forms, schema from ttfrog.exceptions import MalformedRequestError, RecordNotFoundError, UnauthorizedError -from tinydb import where -import re def get_page( @@ -130,6 +130,7 @@ def put(table, path): params = json.loads(request.data.decode())["body"] save_data = getattr(forms, table)(page, params).prepare() app.log.debug("Saving form data...") + app.log.debug(f"{save_data=}") doc = app.db.save(save_data) app.log.debug(f"Saved {dict(doc)}") if not page.doc_id: @@ -143,7 +144,6 @@ def put(table, path): @app.web.route(f"{app.config.API_URI}/search/", methods=["POST"]) @app.web.route(f"{app.config.API_URI}/search/", methods=["POST"], defaults={"space": None}) def search(space): - spaces = app.db.tables() if space: spaces = [space.lower().capitalize()] @@ -152,13 +152,12 @@ def search(space): app.log.debug(f"Searching for records matching query {query}") matches = [] for space in spaces: - for page in app.db.table(space).search(where('name').matches(query, re.IGNORECASE), recurse=False): + for page in app.db.table(space).search(where("name").matches(query, re.IGNORECASE), recurse=False): if app.authorize(g.user, page, schema.Permissions.READ): app.log.debug(f"Adding search result {dict(page)}") matches.append(dict(page)) return api_response( - response=matches, - error=None if matches else RecordNotFoundError(f"No records matching '{query}'") + response=matches, error=None if matches else RecordNotFoundError(f"No records matching '{query}'") )