Development

This commit is contained in:
Matthew Grotke 2026-05-30 14:57:33 -04:00
parent 113328c566
commit 01a636e842
16 changed files with 388 additions and 502 deletions

View file

@ -1,10 +1,9 @@
import os
from pathlib import Path
from flask import Blueprint, request, redirect, flash, session
from auth import require_level
from config_utils import (flush_pending_to_queue, get_dashboard_pending,
revert_snapshot_to_config, queued_msg,
SNAPSHOTS_DIR, DASHBOARD_PENDING)
revert_group, queued_msg,
DASHBOARD_PENDING, _db)
_PAGE = Path(__file__).parent.name
@ -40,7 +39,7 @@ def history_revert():
return redirect(f'/{_PAGE}')
succeeded, failed = 0, 0
for uuid in selected_uuids:
msg, ok = revert_snapshot_to_config(uuid)
msg, ok = revert_group(uuid)
if ok:
succeeded += 1
else:
@ -60,14 +59,15 @@ def history_clear():
flash('No items selected.', 'info')
return redirect(f'/{_PAGE}')
count = 0
for fname in os.listdir(SNAPSHOTS_DIR):
if not fname.endswith('.json'):
continue
if any(fname.endswith(f'-{uuid}.json') for uuid in selected_uuids):
fpath = os.path.join(SNAPSHOTS_DIR, fname)
if os.path.isfile(fpath):
os.remove(fpath)
count += 1
conn = _db()
try:
for uid in selected_uuids:
conn.execute('DELETE FROM changes WHERE group_id=?', (uid,))
result = conn.execute('DELETE FROM groups WHERE uuid=?', (uid,))
count += result.rowcount
conn.commit()
finally:
conn.close()
plural = 's' if count != 1 else ''
flash(f'{count} history record{plural} cleared.', 'success')
return redirect(f'/{_PAGE}')