mirror of https://gitlab.com/tildes/tildes.git
Browse Source
Migrate to Marshmallow 4.0 way of passing context to schemas
Migrate to Marshmallow 4.0 way of passing context to schemas
https://marshmallow.readthedocs.io/en/latest/upgrading.html#new-context-apimerge-requests/171/head
10 changed files with 81 additions and 25 deletions
-
6tildes/tildes/json.py
-
4tildes/tildes/resources/group.py
-
30tildes/tildes/schemas/context.py
-
5tildes/tildes/schemas/group.py
-
11tildes/tildes/schemas/user.py
-
6tildes/tildes/views/api/web/user.py
-
26tildes/tildes/views/decorators.py
-
6tildes/tildes/views/login.py
-
6tildes/tildes/views/register.py
-
6tildes/tildes/views/settings.py
@ -0,0 +1,30 @@ |
|||
# Copyright (c) 2018 Tildes contributors <code@tildes.net> |
|||
# SPDX-License-Identifier: AGPL-3.0-or-later |
|||
|
|||
"""Context variables that can be used with Marshmallow schemas.""" |
|||
import typing |
|||
|
|||
from marshmallow.experimental.context import Context |
|||
|
|||
|
|||
class TildesContext(typing.TypedDict, total=False): |
|||
"""Context for Tildes Marshmallow schemas. |
|||
|
|||
For convenience, we use one unified class instead of one per schema, |
|||
so it can be passed down through different schemas in a subgraph. |
|||
For example, if a Topic contains a reference to a User, |
|||
one instance of TildesContext can configure both the Topic and User. |
|||
""" |
|||
|
|||
# Applies to UserSchema |
|||
hide_username: bool |
|||
# Applies to UserSchema |
|||
check_breached_passwords: bool |
|||
# Applies to UserSchema |
|||
username_trim_whitespace: bool |
|||
|
|||
# Applies to GroupSchema |
|||
fix_path_capitalization: bool |
|||
|
|||
|
|||
TildesSchemaContext = Context[TildesContext] |
Write
Preview
Loading…
Cancel
Save
Reference in new issue