linuxrouter/docker/routlin-dash/app/action_actions.py

49 lines
1.8 KiB
Python
Raw Normal View History

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 16:38:08 -04:00
from config_utils import (flush_pending_to_queue, flush_selected_to_queue,
delete_pending_by_uuids, get_dashboard_pending,
_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 14:12:52 -04:00
@bp.route('/action/actions_cardoptions_save', methods=['POST'])
2026-05-23 00:27:37 -04:00
@require_level('administrator')
2026-05-25 14:12:52 -04:00
def actions_cardoptions_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 16:07:21 -04:00
@bp.route('/action/actions_cardpendingchanges_applynow', methods=['POST'])
2026-05-23 00:27:37 -04:00
@require_level('administrator')
2026-05-25 16:07:21 -04:00
def actions_cardpendingchanges_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 14:12:52 -04:00
@bp.route('/action/actions_cardpendingchanges_revertselected', methods=['POST'])
2026-05-23 00:27:37 -04:00
@require_level('administrator')
2026-05-25 14:12:52 -04:00
def actions_cardpendingchanges_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)
delete_pending_by_uuids(selected_uuids)
flash('Selected changes reverted.', 'success')
2026-05-23 00:27:37 -04:00
return redirect(_VIEW)