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,
|
|
|
|
|
revert_snapshot_to_core,
|
2026-05-25 16:38:08 -04:00
|
|
|
_is_locked, _format_timing, _seconds_until_next_run)
|
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-23 00:27:37 -04:00
|
|
|
if _is_locked():
|
|
|
|
|
msg = 'Changes queued. They are being applied now.'
|
|
|
|
|
else:
|
|
|
|
|
timing = _format_timing(_seconds_until_next_run())
|
|
|
|
|
if timing:
|
|
|
|
|
msg = f'Changes queued. They will be applied {timing}.'
|
|
|
|
|
else:
|
|
|
|
|
msg = 'Changes queued. The processing service is not running.'
|
|
|
|
|
flash(msg, 'success')
|
|
|
|
|
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:
|
|
|
|
|
msg, ok = revert_snapshot_to_core(uuid)
|
|
|
|
|
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)
|