Switch to String fields by default
This commit is contained in:
parent
fff34948d2
commit
ce2c65cce1
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user