From 105cf4a0441fd37712bb5169b1c92c3f6a35f79b Mon Sep 17 00:00:00 2001 From: Midgard Date: Wed, 25 May 2022 13:55:31 +0200 Subject: [PATCH] Revert "Don't crash on orders that don't have a slug" This reverts commit ff0ea068def1abd2e25cb39db9720c2d8359a2a2. The next commit (Create a slug for old orders in the migration) will change our strategy of writing code to handle the legacy slugless orders: we will generate a slug for old orders. --- app/models/order.py | 16 ---------------- app/notification.py | 4 ++-- app/templates/order.html | 22 ++++++++++----------- app/templates/order_prices.html | 6 +++--- app/templates/utils.html | 2 +- app/views/order.py | 34 ++++++++++++++++----------------- 6 files changed, 33 insertions(+), 51 deletions(-) diff --git a/app/models/order.py b/app/models/order.py index b7fe624..6e5391c 100644 --- a/app/models/order.py +++ b/app/models/order.py @@ -132,19 +132,3 @@ class Order(db.Model): def can_modify_payment(self, user_id: int) -> bool: user = User.query.filter_by(id=user_id).first() return user and (user.is_admin() or user == self.courier) - - @staticmethod - def get_by_slug(slug: str) -> "typing.Optional[Order]": - """ - Find an order by slug. Also matches orders by ID if they don't have a slug - """ - order_id = None - try: - order_id = int(slug) - except: - pass - - return Order.query.filter( - (Order.slug == slug) | - ((Order.slug == None) & (Order.id == order_id)) - ).first() diff --git a/app/notification.py b/app/notification.py index d6cf1cb..5569f2f 100644 --- a/app/notification.py +++ b/app/notification.py @@ -18,7 +18,7 @@ def webhook_text(order: Order) -> typing.Optional[str]: if order.courier is not None: # pylint: disable=C0301, C0209 return " {3} is going to {1}, order <{0}|here>! Deadline in {2} minutes!".format( - url_for("order_bp.order_from_slug", order_slug=order.slug or order.id, _external=True), + url_for("order_bp.order_from_slug", order_slug=order.slug, _external=True), order.location_name, remaining_minutes(order.stoptime), order.courier.username.title(), @@ -28,7 +28,7 @@ def webhook_text(order: Order) -> typing.Optional[str]: return " New order for {}. Deadline in {} minutes. <{}|Open here.>".format( order.location_name, remaining_minutes(order.stoptime), - url_for("order_bp.order_from_slug", order_slug=order.slug or order.id, _external=True), + url_for("order_bp.order_from_slug", order_slug=order.slug, _external=True), ) diff --git a/app/templates/order.html b/app/templates/order.html index 5d9965a..0ad5611 100644 --- a/app/templates/order.html +++ b/app/templates/order.html @@ -23,7 +23,7 @@