From ce2c65cce1040f756f70187c9c66cec88219fc0a Mon Sep 17 00:00:00 2001 From: evilchili Date: Sun, 2 Nov 2025 00:15:56 -0700 Subject: [PATCH] Switch to String fields by default --- src/ttfrog/schema.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/ttfrog/schema.py b/src/ttfrog/schema.py index b10f259..62ebe26 100644 --- a/src/ttfrog/schema.py +++ b/src/ttfrog/schema.py @@ -13,14 +13,14 @@ from grung.objects import ( Collection, DateTime, Dict, - Field, Password, Pointer, Record, + String, TextFilePointer, Timestamp, ) -from grung.validators import PatternValidator +from grung.validators import PatternValidator, LengthValidator from tinydb import where from ttfrog.exceptions import MalformedRequestError @@ -68,7 +68,7 @@ class Page(Record): *super().fields(), # The URI for the page, relative to the app's VIEW_URI - Field("uri", unique=True, validators=[ + String("uri", unique=True, validators=[ PatternValidator(re.compile( r""" ^ # match from beginning of line @@ -83,11 +83,14 @@ class Page(Record): $ # until the end of the string """, re.IGNORECASE | re.VERBOSE - )) + )), ]), # The portion of the URI after the last / - Field("name", validators=[PatternValidator(re.compile(r'^(?:/|(?:[0-9a-z]+))$', re.IGNORECASE))]), + String("name", validators=[ + PatternValidator(re.compile(r'^(?:/|(?:[0-9a-z]+))$', re.IGNORECASE)), + LengthValidator(min=1, max=64), + ]), # The pages that exist below this page's URI Collection("members", member_type=Page), @@ -212,7 +215,7 @@ class Entity(Page): def fields(cls): inherited = [field for field in super().fields() if field.name not in ("members", "uid")] return inherited + [ - Field("name", primary_key=True), + String("name", primary_key=True), ] def has_permission(self, record: Record, requested: str) -> bool | None: @@ -238,10 +241,7 @@ class User(Entity): @classmethod def fields(cls): - return super().fields() + [ - Field("email", unique=True), - Password("password"), - ] + return super().fields() + [String("email", unique=True), Password("password")] def update(self, **data): self.author = None if self == g.user else g.user