Skip to content

Commit

Permalink
Fix some field key casing errors
Browse files Browse the repository at this point in the history
  • Loading branch information
bkis committed Aug 30, 2023
1 parent 3be8af3 commit 5f34e04
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 38 deletions.
14 changes: 9 additions & 5 deletions Tekst-API/tekst/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,11 @@ async def on_after_register(
self, user: UserDocument, request: Request | None = None
):
if not _cfg.security.users_active_by_default:
admins = await UserDocument.find({"isSuperuser": True}).limit(10).to_list()
admins = (
await UserDocument.find(UserDocument.is_superuser == True) # noqa: E712
.limit(10)
.to_list()
)
for admin in admins:
send_email(
user,
Expand All @@ -163,13 +167,13 @@ async def on_after_update(
update_dict: dict[str, Any],
request: Request | None = None,
):
if "isActive" in update_dict:
if update_dict.get("isActive"):
if "is_active" in update_dict:
if update_dict.get("is_active"):
send_email(user, TemplateIdentifier.ACTIVATED)
else:
send_email(user, TemplateIdentifier.DEACTIVATED)
if "isSuperuser" in update_dict:
if update_dict.get("isSuperuser"):
if "is_superuser" in update_dict:
if update_dict.get("is_superuser"):
send_email(user, TemplateIdentifier.SUPERUSER_SET)
else:
send_email(user, TemplateIdentifier.SUPERUSER_UNSET)
Expand Down
2 changes: 1 addition & 1 deletion Tekst-API/tekst/models/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ async def insert(self, **kwargs):
return await super().insert(**kwargs)

async def apply(self, updates: dict, **kwargs):
updates["modifiedAt"] = datetime.utcnow()
updates["modified_at"] = datetime.utcnow()
return await self.set(decamelize(updates), **kwargs)

class Settings:
Expand Down
58 changes: 29 additions & 29 deletions Tekst-API/tekst/utils/importer.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
from collections import deque
# from collections import deque

from tekst.models.text import NodeDocument, TextDocument, TextRead
# from tekst.models.text import NodeDocument, TextDocument, TextRead


async def import_text(data: dict) -> TextRead | None:
# create and save text object
text = await TextDocument(**data).create()
stack = deque()
positions = [0]
# async def import_text(data: dict) -> TextRead | None:
# # create and save text object
# text = await TextDocument(**data).create()
# stack = deque()
# positions = [0]

# push nodes of first structure level onto stack
for node in data.get("nodes", []):
node["parentId"] = None
node["textId"] = text.id
node["level"] = 0
node["position"] = positions[0]
stack.append(node)
positions[0] += 1
# # push nodes of first structure level onto stack
# for node in data.get("nodes", []):
# node["parentId"] = None
# node["textId"] = text.id
# node["level"] = 0
# node["position"] = positions[0]
# stack.append(node)
# positions[0] += 1

# process stack
while stack:
node_data = stack.pop()
node = await NodeDocument(**node_data).create()
# # process stack
# while stack:
# node_data = stack.pop()
# node = await NodeDocument(**node_data).create()

for u in node_data.get("nodes", []):
u["parentId"] = node.id
u["textId"] = text.id
u["level"] = node.level + 1
if len(positions) <= u["level"]:
positions.append(0)
u["position"] = positions[u["level"]]
positions[u["level"]] += 1
stack.append(u)
# for u in node_data.get("nodes", []):
# u["parentId"] = node.id
# u["textId"] = text.id
# u["level"] = node.level + 1
# if len(positions) <= u["level"]:
# positions.append(0)
# u["position"] = positions[u["level"]]
# positions[u["level"]] += 1
# stack.append(u)

return text
# return text
10 changes: 7 additions & 3 deletions Tekst-API/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from asgi_lifespan import LifespanManager
from httpx import AsyncClient, Response
from humps import decamelize
from tekst.app import app
from tekst.auth import _create_user
from tekst.config import TekstConfig, get_config
Expand Down Expand Up @@ -43,7 +44,7 @@ def anyio_backend():
def test_data(request) -> dict:
"""Returns all shared test data"""
datadir = Path(request.config.rootdir) / "tests/data"
return json.loads((datadir / "test-data.json").read_text())
return decamelize(json.loads((datadir / "test-data.json").read_text()))


# @pytest.fixture(scope="session")
Expand Down Expand Up @@ -104,8 +105,11 @@ async def _insert_test_data(*collections: str) -> str | None:
await NodeDocument(text_id=text.id, **doc).create()
if "layers" in collections:
for doc in test_data["layers"]:
layer_model = layer_type_manager.get(doc["layerType"]).get_layer_model()
layer_document_model = layer_model.get_document_model()
layer_document_model = (
layer_type_manager.get(doc["layer_type"])
.get_layer_model()
.get_document_model()
)
await layer_document_model(text_id=text.id, **doc).create()

return str(text.id) if text else None
Expand Down

0 comments on commit 5f34e04

Please sign in to comment.