first commit
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
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()
|
||||
Reference in New Issue
Block a user