Files
Forge-Engine/screens/screens_repo/move_screen.py
T
williamandwilliam 3f4ebc4527
Build and deploy / build-and-push (push) Successful in 17s
Build and deploy / deploy (push) Successful in 10s
first commit
2026-08-21 16:23:49 +02:00

22 lines
801 B
Python

import db
from .list_screens import list_screens
def move_screen(slug, screen_id, direction):
"""direction: -1 (monter, l'écran devient plus tôt dans l'enchaînement)
ou +1 (descendre) — échange l'order_index avec l'écran voisin."""
screens_ = list_screens(slug)
idx = next((i for i, s in enumerate(screens_) if s["id"] == screen_id), None)
if idx is None:
return
swap_idx = idx + direction
if swap_idx < 0 or swap_idx >= len(screens_):
return
a, b = screens_[idx], screens_[swap_idx]
conn = db.connect(slug)
conn.execute("UPDATE _screens SET order_index = ? WHERE id = ?", (b["order_index"], a["id"]))
conn.execute("UPDATE _screens SET order_index = ? WHERE id = ?", (a["order_index"], b["id"]))
conn.commit()
conn.close()