48 lines
1.7 KiB
Python
48 lines
1.7 KiB
Python
from flask import Blueprint, request, redirect, flash, session
|
|
from auth import require_level
|
|
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)
|
|
|
|
bp = Blueprint('action_actions', __name__)
|
|
|
|
_VIEW = '/view/view_actions'
|
|
|
|
|
|
@bp.route('/action/actions_cardpending_save', methods=['POST'])
|
|
@require_level('administrator')
|
|
def actions_cardpending_save():
|
|
session['apply_changes_immediately'] = 'apply_changes_immediately' in request.form
|
|
flash('Preference saved.', 'success')
|
|
return redirect(_VIEW)
|
|
|
|
|
|
@bp.route('/action/actions_cardpending_applynow', methods=['POST'])
|
|
@require_level('administrator')
|
|
def actions_cardpending_applynow():
|
|
if not get_dashboard_pending():
|
|
flash('No pending changes to apply.', 'info')
|
|
return redirect(_VIEW)
|
|
flush_pending_to_queue()
|
|
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)
|
|
|
|
|
|
@bp.route('/action/actions_cardpending_revertselected', methods=['POST'])
|
|
@require_level('administrator')
|
|
def actions_cardpending_revertselected():
|
|
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')
|
|
return redirect(_VIEW)
|