Ruff format
This commit is contained in:
+5
-15
@@ -130,9 +130,7 @@ async def save_page(
|
|||||||
if i18n.add_patch(data, node, path, lang, page.markdown):
|
if i18n.add_patch(data, node, path, lang, page.markdown):
|
||||||
_invalidate_pages()
|
_invalidate_pages()
|
||||||
return
|
return
|
||||||
with kanta.transaction(
|
with kanta.transaction("page", user=request.headers.get("remote-user"), extra=path):
|
||||||
"page", user=request.headers.get("remote-user"), extra=path
|
|
||||||
):
|
|
||||||
node = _ensure(data.menu, path)
|
node = _ensure(data.menu, path)
|
||||||
node.title = page.title
|
node.title = page.title
|
||||||
node.chunks = store_chunks(data.chunks, page.markdown)
|
node.chunks = store_chunks(data.chunks, page.markdown)
|
||||||
@@ -242,9 +240,7 @@ async def update_structure(op: StructureOp, request: Request) -> None:
|
|||||||
if op.title is not None
|
if op.title is not None
|
||||||
else "structure:reorder"
|
else "structure:reorder"
|
||||||
)
|
)
|
||||||
with kanta.transaction(
|
with kanta.transaction(action, user=request.headers.get("remote-user"), extra=path):
|
||||||
action, user=request.headers.get("remote-user"), extra=path
|
|
||||||
):
|
|
||||||
if op.title is not None:
|
if op.title is not None:
|
||||||
node.title = op.title
|
node.title = op.title
|
||||||
if target is not None and target != path:
|
if target is not None and target != path:
|
||||||
@@ -307,9 +303,7 @@ class SettingsIn(BaseModel):
|
|||||||
@router.put("/_api/settings", status_code=204)
|
@router.put("/_api/settings", status_code=204)
|
||||||
async def put_settings(settings: SettingsIn, request: Request) -> None:
|
async def put_settings(settings: SettingsIn, request: Request) -> None:
|
||||||
"""Update site-wide settings; invalidates cached pages and ETags."""
|
"""Update site-wide settings; invalidates cached pages and ETags."""
|
||||||
with kanta.transaction(
|
with kanta.transaction("settings", user=request.headers.get("remote-user")):
|
||||||
"settings", user=request.headers.get("remote-user")
|
|
||||||
):
|
|
||||||
data.brand = settings.brand
|
data.brand = settings.brand
|
||||||
data.brand_html = settings.brand_html
|
data.brand_html = settings.brand_html
|
||||||
data.theme = settings.theme
|
data.theme = settings.theme
|
||||||
@@ -335,9 +329,7 @@ async def delete_translations(request: Request) -> None:
|
|||||||
translators). User patches are kept; the availability index
|
translators). User patches are kept; the availability index
|
||||||
(node.langs) is rebuilt from them — patches alone still make a language
|
(node.langs) is rebuilt from them — patches alone still make a language
|
||||||
exist on a page."""
|
exist on a page."""
|
||||||
with kanta.transaction(
|
with kanta.transaction("translate:reset", user=request.headers.get("remote-user")):
|
||||||
"translate:reset", user=request.headers.get("remote-user")
|
|
||||||
):
|
|
||||||
i18n.clear_translations(data)
|
i18n.clear_translations(data)
|
||||||
_invalidate_pages()
|
_invalidate_pages()
|
||||||
# Fragments rejected this run (segment validation) stay skipped no
|
# Fragments rejected this run (segment validation) stay skipped no
|
||||||
@@ -376,9 +368,7 @@ async def toggle_task_endpoint(body: ToggleTaskIn, request: Request) -> dict[str
|
|||||||
new_markdown = toggle_task(node_markdown(data, node) or "", body.index)
|
new_markdown = toggle_task(node_markdown(data, node) or "", body.index)
|
||||||
if new_markdown is None:
|
if new_markdown is None:
|
||||||
raise HTTPException(400, "invalid task index")
|
raise HTTPException(400, "invalid task index")
|
||||||
with kanta.transaction(
|
with kanta.transaction("page", user=request.headers.get("remote-user"), extra=path):
|
||||||
"page", user=request.headers.get("remote-user"), extra=path
|
|
||||||
):
|
|
||||||
# Re-chunk like any save: only the chunk containing the toggled
|
# Re-chunk like any save: only the chunk containing the toggled
|
||||||
# checkbox gets a new hash, the rest keep theirs.
|
# checkbox gets a new hash, the rest keep theirs.
|
||||||
node.chunks = store_chunks(data.chunks, new_markdown)
|
node.chunks = store_chunks(data.chunks, new_markdown)
|
||||||
|
|||||||
@@ -483,7 +483,9 @@ _GAP_S = 0.6
|
|||||||
_MATCH = 0.3
|
_MATCH = 0.3
|
||||||
|
|
||||||
|
|
||||||
def _find_mark(src: list[str], units: list[re.Match], start: int) -> tuple[int, int] | None:
|
def _find_mark(
|
||||||
|
src: list[str], units: list[re.Match], start: int
|
||||||
|
) -> tuple[int, int] | None:
|
||||||
"""Locate a mark's source words in the translation's units (from unit
|
"""Locate a mark's source words in the translation's units (from unit
|
||||||
index ``start`` on), as the (start, end) unit-index span of the best
|
index ``start`` on), as the (start, end) unit-index span of the best
|
||||||
fuzzy alignment; None when no alignment is convincing (the caller falls
|
fuzzy alignment; None when no alignment is convincing (the caller falls
|
||||||
@@ -508,7 +510,10 @@ def _find_mark(src: list[str], units: list[re.Match], start: int) -> tuple[int,
|
|||||||
back[i][0] = (i - 1, 0)
|
back[i][0] = (i - 1, 0)
|
||||||
for j in range(1, m + 1):
|
for j in range(1, m + 1):
|
||||||
options = [
|
options = [
|
||||||
(dp[i - 1][j - 1] + _word_sim(src[i - 1], tgt[j - 1]) - _MATCH, (i - 1, j - 1)),
|
(
|
||||||
|
dp[i - 1][j - 1] + _word_sim(src[i - 1], tgt[j - 1]) - _MATCH,
|
||||||
|
(i - 1, j - 1),
|
||||||
|
),
|
||||||
(dp[i][j - 1] - _GAP_T, (i, j - 1)),
|
(dp[i][j - 1] - _GAP_T, (i, j - 1)),
|
||||||
(dp[i - 1][j] - _GAP_S, (i - 1, j)),
|
(dp[i - 1][j] - _GAP_S, (i - 1, j)),
|
||||||
]
|
]
|
||||||
|
|||||||
Reference in New Issue
Block a user