Add system reset button to admin dashboard with confirmation
This commit is contained in:
parent
3db7d6449e
commit
c532f1dc1c
3 changed files with 40 additions and 1 deletions
24
app.py
24
app.py
|
|
@ -1,4 +1,5 @@
|
||||||
import os
|
import os
|
||||||
|
import shutil
|
||||||
import smtplib
|
import smtplib
|
||||||
import ssl
|
import ssl
|
||||||
from email.message import EmailMessage
|
from email.message import EmailMessage
|
||||||
|
|
@ -8,7 +9,7 @@ from flask import Flask, request, render_template, redirect, url_for, flash, ses
|
||||||
from werkzeug.utils import secure_filename
|
from werkzeug.utils import secure_filename
|
||||||
|
|
||||||
from config import Config
|
from config import Config
|
||||||
from models import init_db, close_db, create_request, get_request_by_id, get_request_by_token, list_requests, update_request, now_utc, delete_request
|
from models import init_db, close_db, create_request, get_request_by_id, get_request_by_token, list_requests, update_request, now_utc, delete_request, reset_all_requests
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
app.config.from_object(Config)
|
app.config.from_object(Config)
|
||||||
|
|
@ -292,6 +293,27 @@ def admin_delete_request(rid):
|
||||||
flash(f'Request #{rid} deleted.', 'success')
|
flash(f'Request #{rid} deleted.', 'success')
|
||||||
return redirect(url_for('admin_dashboard'))
|
return redirect(url_for('admin_dashboard'))
|
||||||
|
|
||||||
|
@app.route('/admin/reset', methods=['POST'])
|
||||||
|
def admin_reset_system():
|
||||||
|
redir = require_admin()
|
||||||
|
if redir:
|
||||||
|
return redir
|
||||||
|
|
||||||
|
upload_root = Path(current_app.config['UPLOAD_FOLDER'])
|
||||||
|
if upload_root.exists():
|
||||||
|
for entry in upload_root.iterdir():
|
||||||
|
try:
|
||||||
|
if entry.is_file():
|
||||||
|
entry.unlink()
|
||||||
|
elif entry.is_dir():
|
||||||
|
shutil.rmtree(entry)
|
||||||
|
except OSError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
reset_all_requests()
|
||||||
|
flash('System reset complete. All orders and files have been cleared.', 'success')
|
||||||
|
return redirect(url_for('admin_dashboard'))
|
||||||
|
|
||||||
# ---------------- init ----------------
|
# ---------------- init ----------------
|
||||||
|
|
||||||
@app.cli.command('init-db')
|
@app.cli.command('init-db')
|
||||||
|
|
|
||||||
|
|
@ -98,3 +98,8 @@ def delete_request(request_id):
|
||||||
db = get_db()
|
db = get_db()
|
||||||
db.execute('DELETE FROM requests WHERE id = ?', (request_id,))
|
db.execute('DELETE FROM requests WHERE id = ?', (request_id,))
|
||||||
db.commit()
|
db.commit()
|
||||||
|
|
||||||
|
def reset_all_requests():
|
||||||
|
db = get_db()
|
||||||
|
db.execute('DELETE FROM requests')
|
||||||
|
db.commit()
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,10 @@ tr:hover{background:#2d3748}
|
||||||
.logout{float:right;color:#f87171;text-decoration:none}
|
.logout{float:right;color:#f87171;text-decoration:none}
|
||||||
.flash{padding:.8rem;background:#064e3b;border-radius:.5rem;margin-bottom:1rem}
|
.flash{padding:.8rem;background:#064e3b;border-radius:.5rem;margin-bottom:1rem}
|
||||||
.flash.error{background:#450a0a}
|
.flash.error{background:#450a0a}
|
||||||
|
.reset-box{margin-top:2rem;padding:1rem;background:#450a0a;border:1px solid #7f1d1d;border-radius:.5rem}
|
||||||
|
.reset-box form{display:inline}
|
||||||
|
.reset-box button{background:#dc2626;color:#fff}
|
||||||
|
.reset-box button:hover{background:#b91c1c}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
@ -78,6 +82,14 @@ tr:hover{background:#2d3748}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
<div class="reset-box">
|
||||||
|
<h2>⚠️ Reset System</h2>
|
||||||
|
<p>Use this once at the start of an event to clear all orders and uploaded files.</p>
|
||||||
|
<form method="POST" action="{{ url_for('admin_reset_system') }}" onsubmit="return confirm('ARE YOU SURE? This will delete ALL requests and ALL uploaded files. This cannot be undone.')">
|
||||||
|
<button type="submit">Reset System</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
||||||
Reference in a new issue