Switch to String fields by default

This commit is contained in:
evilchili 2025-11-02 00:15:56 -07:00
parent fff34948d2
commit ce2c65cce1

View File

@ -13,14 +13,14 @@ from grung.objects import (
Collection, Collection,
DateTime, DateTime,
Dict, Dict,
Field,
Password, Password,
Pointer, Pointer,
Record, Record,
String,
TextFilePointer, TextFilePointer,
Timestamp, Timestamp,
) )
from grung.validators import PatternValidator from grung.validators import PatternValidator, LengthValidator
from tinydb import where from tinydb import where
from ttfrog.exceptions import MalformedRequestError from ttfrog.exceptions import MalformedRequestError
@ -68,7 +68,7 @@ class Page(Record):
*super().fields(), *super().fields(),
# The URI for the page, relative to the app's VIEW_URI # 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( PatternValidator(re.compile(
r""" r"""
^ # match from beginning of line ^ # match from beginning of line
@ -83,11 +83,14 @@ class Page(Record):
$ # until the end of the string $ # until the end of the string
""", """,
re.IGNORECASE | re.VERBOSE re.IGNORECASE | re.VERBOSE
)) )),
]), ]),
# The portion of the URI after the last / # 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 # The pages that exist below this page's URI
Collection("members", member_type=Page), Collection("members", member_type=Page),
@ -212,7 +215,7 @@ class Entity(Page):
def fields(cls): def fields(cls):
inherited = [field for field in super().fields() if field.name not in ("members", "uid")] inherited = [field for field in super().fields() if field.name not in ("members", "uid")]
return inherited + [ return inherited + [
Field("name", primary_key=True), String("name", primary_key=True),
] ]
def has_permission(self, record: Record, requested: str) -> bool | None: def has_permission(self, record: Record, requested: str) -> bool | None:
@ -238,10 +241,7 @@ class User(Entity):
@classmethod @classmethod
def fields(cls): def fields(cls):
return super().fields() + [ return super().fields() + [String("email", unique=True), Password("password")]
Field("email", unique=True),
Password("password"),
]
def update(self, **data): def update(self, **data):
self.author = None if self == g.user else g.user self.author = None if self == g.user else g.user