formatting
This commit is contained in:
parent
f6efbeb54a
commit
68cfd0e7f6
|
|
@ -159,7 +159,7 @@ API_URI=/_/v1/
|
||||||
|
|
||||||
if "/" in uri:
|
if "/" in uri:
|
||||||
(parent_uri, page_name) = uri.rsplit("/", 1)
|
(parent_uri, page_name) = uri.rsplit("/", 1)
|
||||||
if parent_uri == 'Page':
|
if parent_uri == "Page":
|
||||||
parent_uri = None
|
parent_uri = None
|
||||||
search_uri = page_name
|
search_uri = page_name
|
||||||
else:
|
else:
|
||||||
|
|
@ -169,7 +169,6 @@ API_URI=/_/v1/
|
||||||
# self.log.debug("\n".join([f"{p.doc_id}: {p.uri}" for p in table.all()]))
|
# 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)
|
page = table.get(where("uri") == search_uri, recurse=False)
|
||||||
if not page:
|
if not page:
|
||||||
|
|
||||||
# load the parent to check for write permissions
|
# 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=}")
|
# 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
|
parent_table = table if parent_uri and "/" in parent_uri else self.db.Page
|
||||||
|
|
|
||||||
|
|
@ -56,6 +56,7 @@ def bootstrap():
|
||||||
|
|
||||||
# create the users
|
# create the users
|
||||||
guest = users.add_member(schema.User(name="guest", body=b"# guest"))
|
guest = users.add_member(schema.User(name="guest", body=b"# guest"))
|
||||||
|
|
||||||
admin = users.add_member(
|
admin = users.add_member(
|
||||||
schema.User(name=app.config.ADMIN_USERNAME, password="fnord", email=app.config.ADMIN_EMAIL, body=b"# fnord")
|
schema.User(name=app.config.ADMIN_USERNAME, password="fnord", email=app.config.ADMIN_EMAIL, body=b"# fnord")
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
|
import logging
|
||||||
from dataclasses import dataclass, field
|
from dataclasses import dataclass, field
|
||||||
from functools import cached_property
|
from functools import cached_property
|
||||||
import logging
|
|
||||||
|
|
||||||
from flask import g
|
from flask import g
|
||||||
from grung.types import BackReference, Collection, Pointer, Record, Timestamp
|
from grung.types import BackReference, Collection, Pointer, Record, Timestamp
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,8 @@ from __future__ import annotations
|
||||||
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from enum import StrEnum
|
from enum import StrEnum
|
||||||
from typing import List
|
|
||||||
from textwrap import dedent
|
from textwrap import dedent
|
||||||
|
from typing import List
|
||||||
|
|
||||||
from grung.types import (
|
from grung.types import (
|
||||||
BackReference,
|
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.
|
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}
|
# {name}
|
||||||
|
|
||||||
*Overview of this page*
|
*Overview of this page*
|
||||||
|
|
@ -47,7 +49,8 @@ class Page(Record):
|
||||||
|
|
||||||
*Organize your text into logically separted sections.*
|
*Organize your text into logically separted sections.*
|
||||||
|
|
||||||
""")
|
"""
|
||||||
|
)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def fields(cls):
|
def fields(cls):
|
||||||
|
|
@ -222,7 +225,9 @@ class NPC(Page):
|
||||||
"""
|
"""
|
||||||
An NPC, editable as a wiki page.
|
An NPC, editable as a wiki page.
|
||||||
"""
|
"""
|
||||||
default = dedent("""
|
|
||||||
|
default = dedent(
|
||||||
|
"""
|
||||||
# {name}
|
# {name}
|
||||||
*[Ancestry] [Class]*
|
*[Ancestry] [Class]*
|
||||||
|
|
||||||
|
|
@ -236,4 +241,5 @@ class NPC(Page):
|
||||||
* Flaw: **[flaw]**
|
* Flaw: **[flaw]**
|
||||||
* Goal: **[goal]**
|
* Goal: **[goal]**
|
||||||
|
|
||||||
""")
|
"""
|
||||||
|
)
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,11 @@
|
||||||
import json
|
import json
|
||||||
|
import re
|
||||||
|
|
||||||
from flask import Response, g, jsonify, redirect, render_template, request, session, url_for
|
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 import app, forms, schema
|
||||||
from ttfrog.exceptions import MalformedRequestError, RecordNotFoundError, UnauthorizedError
|
from ttfrog.exceptions import MalformedRequestError, RecordNotFoundError, UnauthorizedError
|
||||||
from tinydb import where
|
|
||||||
import re
|
|
||||||
|
|
||||||
|
|
||||||
def get_page(
|
def get_page(
|
||||||
|
|
@ -130,6 +130,7 @@ def put(table, path):
|
||||||
params = json.loads(request.data.decode())["body"]
|
params = json.loads(request.data.decode())["body"]
|
||||||
save_data = getattr(forms, table)(page, params).prepare()
|
save_data = getattr(forms, table)(page, params).prepare()
|
||||||
app.log.debug("Saving form data...")
|
app.log.debug("Saving form data...")
|
||||||
|
app.log.debug(f"{save_data=}")
|
||||||
doc = app.db.save(save_data)
|
doc = app.db.save(save_data)
|
||||||
app.log.debug(f"Saved {dict(doc)}")
|
app.log.debug(f"Saved {dict(doc)}")
|
||||||
if not page.doc_id:
|
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/<string:space>", methods=["POST"])
|
||||||
@app.web.route(f"{app.config.API_URI}/search/", methods=["POST"], defaults={"space": None})
|
@app.web.route(f"{app.config.API_URI}/search/", methods=["POST"], defaults={"space": None})
|
||||||
def search(space):
|
def search(space):
|
||||||
|
|
||||||
spaces = app.db.tables()
|
spaces = app.db.tables()
|
||||||
if space:
|
if space:
|
||||||
spaces = [space.lower().capitalize()]
|
spaces = [space.lower().capitalize()]
|
||||||
|
|
@ -152,13 +152,12 @@ def search(space):
|
||||||
app.log.debug(f"Searching for records matching query {query}")
|
app.log.debug(f"Searching for records matching query {query}")
|
||||||
matches = []
|
matches = []
|
||||||
for space in spaces:
|
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):
|
if app.authorize(g.user, page, schema.Permissions.READ):
|
||||||
app.log.debug(f"Adding search result {dict(page)}")
|
app.log.debug(f"Adding search result {dict(page)}")
|
||||||
matches.append(dict(page))
|
matches.append(dict(page))
|
||||||
return api_response(
|
return api_response(
|
||||||
response=matches,
|
response=matches, error=None if matches else RecordNotFoundError(f"No records matching '{query}'")
|
||||||
error=None if matches else RecordNotFoundError(f"No records matching '{query}'")
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user