Fix bug with form inside form

This commit is contained in:
Midgard 2022-05-02 22:25:06 +02:00
parent cf27a7de8a
commit 03f1e56161
Signed by: midgard
GPG key ID: 511C112F1331BBB4
2 changed files with 8 additions and 7 deletions

View file

@ -267,7 +267,7 @@
<section class="single_column"> <section class="single_column">
<div class="box" id="per_person"> <div class="box" id="per_person">
<h3>Items per person</h3> <h3>Items per person</h3>
<form action="{{ url_for('order_bp.items_user_paid', order_id=order.id) }}" method="post"> <form action="{{ url_for('order_bp.modify_items', order_id=order.id) }}" method="post">
<table class="table table-condensed"> <table class="table table-condensed">
<thead> <thead>
<tr><th>Total</th><th>Name</th><th>Items</th></tr> <tr><th>Total</th><th>Name</th><th>Items</th></tr>
@ -293,11 +293,9 @@
<li class="{{ 'paid' if item.paid }}"> <li class="{{ 'paid' if item.paid }}">
<div class="actions"> <div class="actions">
{% if item.can_delete(order.id, current_user.id, session.get('anon_name', '')) -%} {% if item.can_delete(order.id, current_user.id, session.get('anon_name', '')) -%}
<form action="{{ url_for('order_bp.delete_item', order_id=order.id, item_id=item.id) }}" method="post" style="display:inline"> <button class="btn btn-link btn-sm" type="submit" name="delete_item" value="{{ item.id }}" style="padding: 0 0.5em;"><span class="glyphicon glyphicon-remove"></span></button>
<button class="btn btn-link btn-sm" type="submit" style="padding: 0 0.5em;"><span class="glyphicon glyphicon-remove"></span></button>
</form>
{% else %} {% else %}
<span class="glyphicon glyphicon-remove" style="color: var(--gray3); padding: 0 0.5em"></span> <span class="glyphicon glyphicon-remove" style="color: var(--gray3); padding: 0 0.5em; cursor: not-allowed"></span>
{%- endif %} {%- endif %}
</div> </div>

View file

@ -226,10 +226,12 @@ def order_item_create(order_id: int) -> typing.Any:
return redirect(url_for("order_bp.order_from_id", order_id=order_id)) return redirect(url_for("order_bp.order_from_id", order_id=order_id))
@order_bp.route("/<order_id>/users_paid", methods=["POST"]) @order_bp.route("/<order_id>/modify_items", methods=["POST"])
@login_required @login_required
# pylint: disable=R1710 # pylint: disable=R1710
def items_user_paid(order_id: int) -> typing.Optional[Response]: def modify_items(order_id: int) -> typing.Optional[Response]:
if "delete_item" in request.form:
return delete_item(order_id, int(request.form["delete_item"]))
user_names = request.form.getlist("user_names") user_names = request.form.getlist("user_names")
if request.form.get("action") == "mark_paid": if request.form.get("action") == "mark_paid":
return set_items_paid(order_id, user_names, True) return set_items_paid(order_id, user_names, True)
@ -237,6 +239,7 @@ def items_user_paid(order_id: int) -> typing.Optional[Response]:
return set_items_paid(order_id, user_names, False) return set_items_paid(order_id, user_names, False)
else: else:
abort(404) abort(404)
return None
def set_items_paid(order_id: int, user_names: typing.Iterable[str], paid: bool): def set_items_paid(order_id: int, user_names: typing.Iterable[str], paid: bool):
total_paid_items = 0 total_paid_items = 0