Allow anonymous order creation

This commit is contained in:
Midgard 2020-07-24 11:34:15 +02:00
parent f0561bcd71
commit 76ac07742e
Signed by: midgard
GPG key ID: 511C112F1331BBB4
3 changed files with 9 additions and 12 deletions

View file

@ -37,15 +37,12 @@ class OrderForm(Form):
def populate(self) -> None:
"Fill in the options for courier for an Order"
if current_user.is_admin():
self.courier_id.choices = [(0, None)] + [
(u.id, u.username) for u in User.query.order_by("username")
]
else:
self.courier_id.choices = [
(0, None),
(current_user.id, current_user.username),
]
self.courier_id.choices = [(0, None)] + (
[(u.id, u.username) for u in User.query.order_by("username")] if current_user.is_admin()
else [(current_user.id, current_user.username)] if current_user.is_authenticated()
else []
)
self.location_id.choices = [(l.id, l.name) for l in location_definitions]
if self.stoptime.data is None:
self.stoptime.data = datetime.now() + timedelta(hours=1)

View file

@ -14,14 +14,14 @@
{% endfor %}
{% else %}
<h4>No orders available.</h4>
{% if not current_user.is_anonymous() %}
{% if form %}
To create an order, fill in the form on the right.
{% else %}
Login to create an order, or ask someone else.
{% endif %}
{%- endif %}
</div>
{% if not current_user.is_anonymous() %}
{% if form %}
<div class="col-md-push-1 col-md-6">
<h3>Create new order</h3>
<div class="row darker">

View file

@ -31,7 +31,7 @@ order_bp = Blueprint("order_bp", "order")
@order_bp.route("/")
def orders(form: OrderForm = None) -> str:
"Generate general order view"
if form is None and not current_user.is_anonymous():
if form is None:
form = OrderForm()
location_id = request.args.get("location_id")
form.location_id.default = location_id