Rename database_error

This commit is contained in:
Gregoo 2025-01-29 22:49:17 +01:00
parent aed7a520bd
commit bba741b4a5
7 changed files with 31 additions and 15 deletions

View File

@ -83,7 +83,7 @@ def admin() -> str:
configuration=BrickConfigurationList.list(), configuration=BrickConfigurationList.list(),
brickset_checkboxes=brickset_checkboxes, brickset_checkboxes=brickset_checkboxes,
database_counters=database_counters, database_counters=database_counters,
database_error=request.args.get('error'), database_error=request.args.get('database_error'),
database_exception=database_exception, database_exception=database_exception,
database_upgrade_needed=database_upgrade_needed, database_upgrade_needed=database_upgrade_needed,
database_version=database_version, database_version=database_version,

View File

@ -38,14 +38,18 @@ def delete() -> str:
return render_template( return render_template(
'admin.html', 'admin.html',
delete_database=True, delete_database=True,
error=request.args.get('error') database_error=request.args.get('database_error')
) )
# Actually delete the database # Actually delete the database
@admin_database_page.route('/delete', methods=['POST']) @admin_database_page.route('/delete', methods=['POST'])
@login_required @login_required
@exception_handler(__file__, post_redirect='admin_database.delete') @exception_handler(
__file__,
post_redirect='admin_database.delete',
error_name='database_error'
)
def do_delete() -> Response: def do_delete() -> Response:
BrickSQL.delete() BrickSQL.delete()
@ -89,14 +93,18 @@ def drop() -> str:
return render_template( return render_template(
'admin.html', 'admin.html',
drop_database=True, drop_database=True,
error=request.args.get('error') database_error=request.args.get('database_error')
) )
# Actually drop the database # Actually drop the database
@admin_database_page.route('/drop', methods=['POST']) @admin_database_page.route('/drop', methods=['POST'])
@login_required @login_required
@exception_handler(__file__, post_redirect='admin_database.drop') @exception_handler(
__file__,
post_redirect='admin_database.drop',
error_name='database_error'
)
def do_drop() -> Response: def do_drop() -> Response:
BrickSQL.drop() BrickSQL.drop()
@ -108,7 +116,11 @@ def do_drop() -> Response:
# Actually upgrade the database # Actually upgrade the database
@admin_database_page.route('/upgrade', methods=['POST']) @admin_database_page.route('/upgrade', methods=['POST'])
@login_required @login_required
@exception_handler(__file__, post_redirect='admin_database.upgrade') @exception_handler(
__file__,
post_redirect='admin_database.upgrade',
error_name='database_error'
)
def do_upgrade() -> Response: def do_upgrade() -> Response:
BrickSQL(failsafe=True).upgrade() BrickSQL(failsafe=True).upgrade()
@ -125,14 +137,18 @@ def upload() -> str:
return render_template( return render_template(
'admin.html', 'admin.html',
import_database=True, import_database=True,
error=request.args.get('error') database_error=request.args.get('database_error')
) )
# Actually import a database # Actually import a database
@admin_database_page.route('/import', methods=['POST']) @admin_database_page.route('/import', methods=['POST'])
@login_required @login_required
@exception_handler(__file__, post_redirect='admin_database.upload') @exception_handler(
__file__,
post_redirect='admin_database.upload',
error_name='database_error'
)
def do_upload() -> Response: def do_upload() -> Response:
file = upload_helper( file = upload_helper(
'database', 'database',
@ -153,7 +169,7 @@ def do_upload() -> Response:
# Upgrade the database # Upgrade the database
@admin_database_page.route('/upgrade', methods=['GET']) @admin_database_page.route('/upgrade', methods=['GET'])
@login_required @login_required
@exception_handler(__file__, post_redirect='admin.admin') @exception_handler(__file__)
def upgrade() -> str | Response: def upgrade() -> str | Response:
database = BrickSQL(failsafe=True) database = BrickSQL(failsafe=True)
@ -166,5 +182,5 @@ def upgrade() -> str | Response:
migrations=BrickSQLMigrationList().pending( migrations=BrickSQLMigrationList().pending(
database.version database.version
), ),
error=request.args.get('error') database_error=request.args.get('database_error')
) )

View File

@ -36,7 +36,7 @@
{{ accordion.footer() }} {{ accordion.footer() }}
{{ accordion.header('Database danger zone', 'database-danger', 'admin', danger=true, class='text-end') }} {{ accordion.header('Database danger zone', 'database-danger', 'admin', danger=true, class='text-end') }}
{% if error %}<div class="alert alert-danger text-start" role="alert"><strong>Error:</strong> {{ error }}.</div>{% endif %} {% if database_error %}<div class="alert alert-danger text-start" role="alert"><strong>Error:</strong> {{ database_error }}.</div>{% endif %}
<a href="{{ url_for('admin_database.upload') }}" class="btn btn-warning" role="button"><i class="ri-upload-line"></i> Import a database file</a> <a href="{{ url_for('admin_database.upload') }}" class="btn btn-warning" role="button"><i class="ri-upload-line"></i> Import a database file</a>
<a href="{{ url_for('admin_database.drop') }}" class="btn btn-danger" role="button"><i class="ri-close-line"></i> Drop the database</a> <a href="{{ url_for('admin_database.drop') }}" class="btn btn-danger" role="button"><i class="ri-close-line"></i> Drop the database</a>
<a href="{{ url_for('admin_database.delete') }}" class="btn btn-danger" role="button"><i class="ri-delete-bin-2-line"></i> Delete the database file</a> <a href="{{ url_for('admin_database.delete') }}" class="btn btn-danger" role="button"><i class="ri-delete-bin-2-line"></i> Delete the database file</a>

View File

@ -2,7 +2,7 @@
{{ accordion.header('Database danger zone', 'database-danger', 'admin', expanded=true, danger=true, class='text-end') }} {{ accordion.header('Database danger zone', 'database-danger', 'admin', expanded=true, danger=true, class='text-end') }}
<form action="{{ url_for('admin_database.do_delete') }}" method="post"> <form action="{{ url_for('admin_database.do_delete') }}" method="post">
{% if error %}<div class="alert alert-danger text-start" role="alert"><strong>Error:</strong> {{ error }}.</div>{% endif %} {% if database_error %}<div class="alert alert-danger text-start" role="alert"><strong>Error:</strong> {{ database_error }}.</div>{% endif %}
<div class="alert alert-danger text-center" role="alert">You are about to <strong>delete the database file</strong>. This action is irreversible.</div> <div class="alert alert-danger text-center" role="alert">You are about to <strong>delete the database file</strong>. This action is irreversible.</div>
<a class="btn btn-danger" href="{{ url_for('admin.admin') }}" role="button"><i class="ri-arrow-left-long-line"></i> Back to the admin</a> <a class="btn btn-danger" href="{{ url_for('admin.admin') }}" role="button"><i class="ri-arrow-left-long-line"></i> Back to the admin</a>
<button type="submit" class="btn btn-danger"><i class="ri-delete-bin-2-line"></i> Delete <strong>the database file</strong></button> <button type="submit" class="btn btn-danger"><i class="ri-delete-bin-2-line"></i> Delete <strong>the database file</strong></button>

View File

@ -2,7 +2,7 @@
{{ accordion.header('Database danger zone', 'database-danger', 'admin', expanded=true, danger=true, class='text-end') }} {{ accordion.header('Database danger zone', 'database-danger', 'admin', expanded=true, danger=true, class='text-end') }}
<form action="{{ url_for('admin_database.do_drop') }}" method="post"> <form action="{{ url_for('admin_database.do_drop') }}" method="post">
{% if error %}<div class="alert alert-danger text-start" role="alert"><strong>Error:</strong> {{ error }}.</div>{% endif %} {% if database_error %}<div class="alert alert-danger text-start" role="alert"><strong>Error:</strong> {{ database_error }}.</div>{% endif %}
<div class="alert alert-danger text-center" role="alert">You are about to <strong>drop all the tables from the database</strong>. This action is irreversible.</div> <div class="alert alert-danger text-center" role="alert">You are about to <strong>drop all the tables from the database</strong>. This action is irreversible.</div>
<a class="btn btn-danger" href="{{ url_for('admin.admin') }}" role="button"><i class="ri-arrow-left-long-line"></i> Back to the admin</a> <a class="btn btn-danger" href="{{ url_for('admin.admin') }}" role="button"><i class="ri-arrow-left-long-line"></i> Back to the admin</a>
<button type="submit" class="btn btn-danger"><i class="ri-close-line"></i> Drop <strong>the whole database</strong></button> <button type="submit" class="btn btn-danger"><i class="ri-close-line"></i> Drop <strong>the whole database</strong></button>

View File

@ -2,7 +2,7 @@
{{ accordion.header('Database danger zone', 'database-danger', 'admin', expanded=true, danger=true) }} {{ accordion.header('Database danger zone', 'database-danger', 'admin', expanded=true, danger=true) }}
<form action="{{ url_for('admin_database.do_upload') }}" method="post" enctype="multipart/form-data"> <form action="{{ url_for('admin_database.do_upload') }}" method="post" enctype="multipart/form-data">
{% if error %}<div class="alert alert-danger text-start" role="alert"><strong>Error:</strong> {{ error }}.</div>{% endif %} {% if database_error %}<div class="alert alert-danger text-start" role="alert"><strong>Error:</strong> {{ database_error }}.</div>{% endif %}
<div class="alert alert-warning text-center" role="alert">You are about to <strong>import a database file</strong>. This will replace the <strong>whole content</strong> of the database. This action is irreversible.</div> <div class="alert alert-warning text-center" role="alert">You are about to <strong>import a database file</strong>. This will replace the <strong>whole content</strong> of the database. This action is irreversible.</div>
<div class="mb-3"> <div class="mb-3">
<label for="database" class="form-label">New database file</label> <label for="database" class="form-label">New database file</label>

View File

@ -2,7 +2,7 @@
{{ accordion.header('Database', 'database', 'admin', expanded=true, icon='database-2-line') }} {{ accordion.header('Database', 'database', 'admin', expanded=true, icon='database-2-line') }}
<form action="{{ url_for('admin_database.do_upgrade') }}" method="post"> <form action="{{ url_for('admin_database.do_upgrade') }}" method="post">
{% if error %}<div class="alert alert-danger text-start" role="alert"><strong>Error:</strong> {{ error }}.</div>{% endif %} {% if database_error %}<div class="alert alert-danger text-start" role="alert"><strong>Error:</strong> {{ database_error }}.</div>{% endif %}
<div class="alert alert-warning text-center" role="alert"> <div class="alert alert-warning text-center" role="alert">
You are about to <strong>upgrade your database file</strong>. This action is irreversible.<br> You are about to <strong>upgrade your database file</strong>. This action is irreversible.<br>
The process shold be lossless, but just to be sure, grab a copy of your database before proceeding.<br> The process shold be lossless, but just to be sure, grab a copy of your database before proceeding.<br>