diff --git a/app/forms.py b/app/forms.py index e75893a..b40a1ee 100644 --- a/app/forms.py +++ b/app/forms.py @@ -14,7 +14,7 @@ from utils import euro_string class OrderForm(Form): "Class which defines the form for a new Order" # pylint: disable=R0903 - courrier_id = SelectField("Courrier", coerce=int) + courier_id = SelectField("Courier", coerce=int) location_id = SelectField( "Location", coerce=int, validators=[validators.required()] ) @@ -25,13 +25,13 @@ class OrderForm(Form): submit_button = SubmitField("Submit") def populate(self) -> None: - "Fill in the options for courrier for an Order" + "Fill in the options for courier for an Order" if current_user.is_admin(): - self.courrier_id.choices = [(0, None)] + [ + self.courier_id.choices = [(0, None)] + [ (u.id, u.username) for u in User.query.order_by("username") ] else: - self.courrier_id.choices = [ + self.courier_id.choices = [ (0, None), (current_user.id, current_user.username), ] diff --git a/app/models/order.py b/app/models/order.py index 1be6106..17309f4 100644 --- a/app/models/order.py +++ b/app/models/order.py @@ -10,18 +10,18 @@ from .user import User class Order(db.Model): "Class used for configuring the Order model in the database" id = db.Column(db.Integer, primary_key=True) - courrier_id = db.Column(db.Integer, nullable=True) + courier_id = db.Column(db.Integer, nullable=True) location_id = db.Column(db.Integer, db.ForeignKey("location.id")) starttime = db.Column(db.DateTime) stoptime = db.Column(db.DateTime) public = db.Column(db.Boolean, default=True) items = db.relationship("OrderItem", backref="order", lazy="dynamic") - def configure(self, courrier: User, location: Location, + def configure(self, courier: User, location: Location, starttime: db.DateTime, stoptime: db.DateTime,) -> None: "Configure the Order" # pylint: disable=W0201 - self.courrier = courrier + self.courier = courier self.location = location self.starttime = starttime self.stoptime = stoptime @@ -69,6 +69,6 @@ class Order(db.Model): if user_id: user = User.query.filter_by(id=user_id).first() print(user) - if self.courrier_id == user_id or (user and user.is_admin()): + if self.courier_id == user_id or (user and user.is_admin()): return True return False diff --git a/app/models/orderitem.py b/app/models/orderitem.py index 06b62c1..9850783 100644 --- a/app/models/orderitem.py +++ b/app/models/orderitem.py @@ -56,6 +56,6 @@ class OrderItem(db.Model): if user_id is None: return False user = User.query.filter(User.id == user_id).first() - if user and (user.is_admin() or user == self.order.courrier): + if user and (user.is_admin() or user == self.order.courier): return True return False diff --git a/app/models/user.py b/app/models/user.py index 463075e..35596d1 100644 --- a/app/models/user.py +++ b/app/models/user.py @@ -10,9 +10,9 @@ class User(db.Model): bias = db.Column(db.Integer) runs = db.relation( "Order", - backref="courrier", - primaryjoin="Order.courrier_id==User.id", - foreign_keys="Order.courrier_id", + backref="courier", + primaryjoin="Order.courier_id==User.id", + foreign_keys="Order.courier_id", ) orderItems = db.relationship("OrderItem", backref="user", lazy="dynamic") diff --git a/app/notification.py b/app/notification.py index 4fe4653..023b346 100644 --- a/app/notification.py +++ b/app/notification.py @@ -15,13 +15,13 @@ def webhook_text(order_item: Order) -> typing.Optional[str]: if "Testlocation" in order_item.location.name: return None - if order_item.courrier is not None: + if order_item.courier is not None: # pylint: disable=C0301 return " {3} is going to {1}, order <{0}|here>! Deadline in {2} minutes!".format( url_for("order_bp.order_from_id", order_id=order_item.id, _external=True), order_item.location.name, remaining_minutes(order_item.stoptime), - order_item.courrier.username.title(), + order_item.courier.username.title(), ) return " New order for {}. Deadline in {} minutes. <{}|Open here.>".format( diff --git a/app/templates/order.html b/app/templates/order.html index 40066f6..6783119 100644 --- a/app/templates/order.html +++ b/app/templates/order.html @@ -1,7 +1,7 @@ {% extends "layout.html" %} {% set active_page = "orders" -%} {% set order_items = order.group_by_user() -%} -{% set courier_or_admin = not current_user.is_anonymous() and (current_user.is_admin() or current_user.id == order.courrier_id) -%} +{% set courier_or_admin = not current_user.is_anonymous() and (current_user.is_admin() or current_user.id == order.courier_id) -%} {% import "utils.html" as util %} @@ -18,8 +18,8 @@ Edit {%- endif %} - courier: {{ order.courrier.username }} - {% if order.courrier == None and not current_user.is_anonymous() %} + courier: {{ order.courier.username }} + {% if order.courier == None and not current_user.is_anonymous() %}
diff --git a/app/templates/order_edit.html b/app/templates/order_edit.html index 143903b..2f28781 100644 --- a/app/templates/order_edit.html +++ b/app/templates/order_edit.html @@ -13,10 +13,10 @@
{{ form.csrf_token }} -
- {{ form.courrier_id.label(class='control-label') }}
- {{ form.courrier_id(class='form-control select') }} - {{ util.render_form_field_errors(form.courrier_id) }} +
+ {{ form.courier_id.label(class='control-label') }}
+ {{ form.courier_id(class='form-control select') }} + {{ util.render_form_field_errors(form.courier_id) }}
{{ form.location_id.label(class='control-label') }} diff --git a/app/templates/orders.html b/app/templates/orders.html index 24ff0e1..1c86c9e 100644 --- a/app/templates/orders.html +++ b/app/templates/orders.html @@ -28,10 +28,10 @@
{{ form.csrf_token }} -
- {{ form.courrier_id.label(class='control-label') }}
- {{ form.courrier_id(class='form-control select') }} - {{ util.render_form_field_errors(form.courrier_id) }} +
+ {{ form.courier_id.label(class='control-label') }}
+ {{ form.courier_id(class='form-control select') }} + {{ util.render_form_field_errors(form.courier_id) }}
{{ form.location_id.label(class='control-label') }} diff --git a/app/views/order.py b/app/views/order.py index f96e848..bb88093 100644 --- a/app/views/order.py +++ b/app/views/order.py @@ -82,7 +82,7 @@ def items_showcase(order_id: int) -> str: def order_edit(order_id: int) -> typing.Union[str, Response]: "Generate order edit view from id" order = Order.query.filter(Order.id == order_id).first() - if current_user.id is not order.courrier_id and \ + if current_user.id is not order.courier_id and \ not current_user.is_admin(): abort(401) if order is None: @@ -135,7 +135,7 @@ def item_paid(order_id: int, item_id: int) -> typing.Optional[Response]: "Indicate payment status for an item in an order" item = OrderItem.query.filter(OrderItem.id == item_id).first() user_id = current_user.id - if item.order.courrier_id == user_id or current_user.admin: + if item.order.courier_id == user_id or current_user.admin: item.paid = True db.session.commit() flash("Paid %s by %s" % (item.product.name, item.get_name()), @@ -162,7 +162,7 @@ def items_user_paid(order_id: int, user_name: str) -> typing.Optional[Response]: current_order = Order.query.filter(Order.id == order_id).first() for item in items: print(item) - if current_order.courrier_id == current_user.id or current_user.admin: + if current_order.courier_id == current_user.id or current_user.admin: for item in items: item.paid = True db.session.commit() @@ -199,8 +199,8 @@ def volunteer(order_id: int) -> Response: order = Order.query.filter(Order.id == order_id).first() if order is None: abort(404) - if order.courrier_id is None or order.courrier_id == 0: - order.courrier_id = current_user.id + if order.courier_id is None or order.courrier_id == 0: + order.courier_id = current_user.id db.session.commit() flash("Thank you for volunteering!") else: @@ -215,14 +215,14 @@ def close_order(order_id: int) -> typing.Optional[Response]: order = Order.query.filter(Order.id == order_id).first() if order is None: abort(404) - if (current_user.id == order.courrier_id or current_user.is_admin()) and ( + if (current_user.id == order.courier_id or current_user.is_admin()) and ( order.stoptime is None or (order.stoptime > datetime.now())): order.stoptime = datetime.now() - if order.courrier_id == 0 or order.courrier_id is None: - courrier = select_user(order.items) - print(courrier) - if courrier is not None: - order.courrier_id = courrier.id + if order.courier_id == 0 or order.courrier_id is None: + courier = select_user(order.items) + print(courier) + if courier is not None: + order.courier_id = courrier.id db.session.commit() return redirect(url_for("order_bp.order_from_id", order_id=order_id)) # The line below is to make sure mypy doesn't say