From 76ac07742ee25bfcc9f1c72360df461945cbfe8d Mon Sep 17 00:00:00 2001 From: Midgard <midgard@zeus.ugent.be> Date: Fri, 24 Jul 2020 11:34:15 +0200 Subject: [PATCH] Allow anonymous order creation --- app/forms.py | 15 ++++++--------- app/templates/orders.html | 4 ++-- app/views/order.py | 2 +- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/app/forms.py b/app/forms.py index 1317c21..7e5600e 100644 --- a/app/forms.py +++ b/app/forms.py @@ -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) diff --git a/app/templates/orders.html b/app/templates/orders.html index e472461..4af44eb 100644 --- a/app/templates/orders.html +++ b/app/templates/orders.html @@ -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"> diff --git a/app/views/order.py b/app/views/order.py index 177c195..341cfaf 100644 --- a/app/views/order.py +++ b/app/views/order.py @@ -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