2026-05-25 13:49:23 -04:00
|
|
|
from flask import Blueprint, request, redirect, flash, session
|
2026-05-23 00:27:37 -04:00
|
|
|
from auth import require_level
|
2026-05-25 21:31:20 -04:00
|
|
|
from config_utils import (flush_pending_to_queue, get_dashboard_pending,
|
2026-05-25 22:44:37 -04:00
|
|
|
revert_snapshot_to_config, queued_msg,
|
2026-05-25 23:57:34 -04:00
|
|
|
_timing_status_msg)
|
2026-05-23 00:27:37 -04:00
|
|
|
|
2026-05-25 13:49:23 -04:00
|
|
|
bp = Blueprint('action_actions', __name__)
|
2026-05-23 00:27:37 -04:00
|
|
|
|
2026-05-25 13:49:23 -04:00
|
|
|
_VIEW = '/view/view_actions'
|
2026-05-23 00:27:37 -04:00
|
|
|
|
|
|
|
|
|
2026-05-25 17:26:51 -04:00
|
|
|
@bp.route('/action/actions_cardpending_save', methods=['POST'])
|
2026-05-23 00:27:37 -04:00
|
|
|
@require_level('administrator')
|
2026-05-25 17:26:51 -04:00
|
|
|
def actions_cardpending_save():
|
2026-05-25 13:49:23 -04:00
|
|
|
session['apply_changes_immediately'] = 'apply_changes_immediately' in request.form
|
|
|
|
|
flash('Preference saved.', 'success')
|
2026-05-23 00:27:37 -04:00
|
|
|
return redirect(_VIEW)
|
|
|
|
|
|
|
|
|
|
|
2026-05-25 17:26:51 -04:00
|
|
|
@bp.route('/action/actions_cardpending_applynow', methods=['POST'])
|
2026-05-23 00:27:37 -04:00
|
|
|
@require_level('administrator')
|
2026-05-25 17:26:51 -04:00
|
|
|
def actions_cardpending_applynow():
|
2026-05-25 16:38:08 -04:00
|
|
|
if not get_dashboard_pending():
|
|
|
|
|
flash('No pending changes to apply.', 'info')
|
2026-05-23 00:27:37 -04:00
|
|
|
return redirect(_VIEW)
|
2026-05-25 16:38:08 -04:00
|
|
|
flush_pending_to_queue()
|
2026-05-25 23:57:34 -04:00
|
|
|
flash(_timing_status_msg(None, 'Changes queued'), 'success')
|
2026-05-25 22:44:37 -04:00
|
|
|
return redirect(_VIEW)
|
|
|
|
|
|
|
|
|
|
|
2026-05-25 21:31:20 -04:00
|
|
|
@bp.route('/action/actions_cardhistory_revertselected', methods=['POST'])
|
2026-05-23 00:27:37 -04:00
|
|
|
@require_level('administrator')
|
2026-05-25 21:31:20 -04:00
|
|
|
def actions_cardhistory_revertselected():
|
2026-05-25 14:50:03 -04:00
|
|
|
selected_uuids = request.form.getlist('selected_uuids')
|
|
|
|
|
if not selected_uuids:
|
|
|
|
|
flash('No items selected.', 'info')
|
|
|
|
|
return redirect(_VIEW)
|
2026-05-25 21:31:20 -04:00
|
|
|
succeeded, failed = 0, 0
|
|
|
|
|
for uuid in selected_uuids:
|
2026-05-25 22:44:37 -04:00
|
|
|
msg, ok = revert_snapshot_to_config(uuid)
|
2026-05-25 21:31:20 -04:00
|
|
|
if ok:
|
|
|
|
|
succeeded += 1
|
|
|
|
|
else:
|
|
|
|
|
flash(msg, 'error')
|
|
|
|
|
failed += 1
|
|
|
|
|
if succeeded:
|
|
|
|
|
plural = 's' if succeeded != 1 else ''
|
|
|
|
|
flash(f'{succeeded} change{plural} reverted.', 'success')
|
2026-05-23 00:27:37 -04:00
|
|
|
return redirect(_VIEW)
|