Rename checkox_error

This commit is contained in:
Gregoo 2025-01-30 09:33:54 +01:00
parent bba741b4a5
commit 4fc96ec38f
3 changed files with 20 additions and 6 deletions

View File

@ -82,6 +82,7 @@ def admin() -> str:
'admin.html', 'admin.html',
configuration=BrickConfigurationList.list(), configuration=BrickConfigurationList.list(),
brickset_checkboxes=brickset_checkboxes, brickset_checkboxes=brickset_checkboxes,
checkbox_error=request.args.get('checkbox_error'),
database_counters=database_counters, database_counters=database_counters,
database_error=request.args.get('database_error'), database_error=request.args.get('database_error'),
database_exception=database_exception, database_exception=database_exception,

View File

@ -27,7 +27,12 @@ admin_checkbox_page = Blueprint(
# Add a checkbox # Add a checkbox
@admin_checkbox_page.route('/add', methods=['POST']) @admin_checkbox_page.route('/add', methods=['POST'])
@login_required @login_required
@exception_handler(__file__, post_redirect='admin.admin', open_checkbox=True) @exception_handler(
__file__,
post_redirect='admin.admin',
error_name='checkbox_error',
open_checkbox=True
)
def add() -> Response: def add() -> Response:
BrickSetCheckbox().from_form(request.form).insert() BrickSetCheckbox().from_form(request.form).insert()
@ -45,14 +50,18 @@ def delete(*, id: str) -> str:
'admin.html', 'admin.html',
delete_checkbox=True, delete_checkbox=True,
checkbox=BrickSetCheckbox().select_specific(id), checkbox=BrickSetCheckbox().select_specific(id),
error=request.args.get('error') error=request.args.get('checkbox_error')
) )
# Actually delete the checkbox # Actually delete the checkbox
@admin_checkbox_page.route('<id>/delete', methods=['POST']) @admin_checkbox_page.route('<id>/delete', methods=['POST'])
@login_required @login_required
@exception_handler(__file__, post_redirect='admin_checkbox.delete') @exception_handler(
__file__,
post_redirect='admin_checkbox.delete',
error_name='checkbox_error'
)
def do_delete(*, id: str) -> Response: def do_delete(*, id: str) -> Response:
checkbox = BrickSetCheckbox().select_specific(id) checkbox = BrickSetCheckbox().select_specific(id)
checkbox.delete() checkbox.delete()
@ -88,7 +97,12 @@ def update_status(*, id: str, name: str) -> Response:
# Rename the checkbox # Rename the checkbox
@admin_checkbox_page.route('<id>/rename', methods=['POST']) @admin_checkbox_page.route('<id>/rename', methods=['POST'])
@login_required @login_required
@exception_handler(__file__, post_redirect='admin.admin', open_checkbox=True) @exception_handler(
__file__,
post_redirect='admin.admin',
error_name='checkbox_error',
open_checkbox=True
)
def rename(*, id: str) -> Response: def rename(*, id: str) -> Response:
checkbox = BrickSetCheckbox().select_specific(id) checkbox = BrickSetCheckbox().select_specific(id)
checkbox.from_form(request.form).rename() checkbox.from_form(request.form).rename()

View File

@ -1,8 +1,7 @@
{% import 'macro/accordion.html' as accordion %} {% import 'macro/accordion.html' as accordion %}
{{ accordion.header('Checkboxes', 'checkbox', 'admin', expanded=open_checkbox, icon='checkbox-line', class='p-0') }} {{ accordion.header('Checkboxes', 'checkbox', 'admin', expanded=open_checkbox, icon='checkbox-line', class='p-0') }}
{% if error %}<div class="alert alert-danger m-2" role="alert"><strong>Error:</strong> {{ error }}.</div>{% endif %} {% if checkbox_error %}<div class="alert alert-danger m-2" role="alert"><strong>Error:</strong> {{ checkbox_error }}.</div>{% endif %}
{% if database_error %}<div class="alert alert-danger m-2" role="alert"><strong>Error:</strong> {{ database_error }}.</div>{% endif %}
<ul class="list-group list-group-flush"> <ul class="list-group list-group-flush">
{% if brickset_checkboxes | length %} {% if brickset_checkboxes | length %}
{% for checkbox in brickset_checkboxes %} {% for checkbox in brickset_checkboxes %}