formatting

This commit is contained in:
evilchili 2025-10-30 20:52:15 -07:00
parent f6efbeb54a
commit 68cfd0e7f6
5 changed files with 19 additions and 14 deletions

View File

@ -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

View File

@ -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")
)

View File

@ -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

View File

@ -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]**
""")
"""
)

View File

@ -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/<string:space>", 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}'")
)