From 7f1ec29786dfcf4b04ba7bbdc44abc29b20c7a11 Mon Sep 17 00:00:00 2001 From: Russell Ballestrini Date: Thu, 7 Jul 2022 11:53:56 -0400 Subject: [PATCH] move active_shop to request.shop modified: make_post_sell/templates/actions_new.j2 modified: make_post_sell/templates/actions_view.j2 modified: make_post_sell/templates/base.j2 modified: make_post_sell/templates/product_new.j2 modified: make_post_sell/views/coupon.py modified: make_post_sell/views/product.py modified: make_post_sell/views/user.py --- make_post_sell/templates/actions_new.j2 | 4 ++-- make_post_sell/templates/actions_view.j2 | 14 +++++++------- make_post_sell/templates/base.j2 | 4 +--- make_post_sell/templates/product_new.j2 | 4 ++-- make_post_sell/views/coupon.py | 23 ++++------------------- make_post_sell/views/product.py | 7 +------ make_post_sell/views/user.py | 2 +- 7 files changed, 18 insertions(+), 40 deletions(-) diff --git a/make_post_sell/templates/actions_new.j2 b/make_post_sell/templates/actions_new.j2 index 907ee9e..fe943d9 100644 --- a/make_post_sell/templates/actions_new.j2 +++ b/make_post_sell/templates/actions_new.j2 @@ -4,9 +4,9 @@
- {% if request.user.active_shop %} + {% if request.shop %} - {{ request.user.active_shop.name }} + {{ request.shop.name }}

diff --git a/make_post_sell/templates/actions_view.j2 b/make_post_sell/templates/actions_view.j2 index d552787..cfb1863 100644 --- a/make_post_sell/templates/actions_view.j2 +++ b/make_post_sell/templates/actions_view.j2 @@ -4,29 +4,29 @@
- {% if request.user.active_shop %} + {% if request.shop %} - {{ request.user.active_shop.name }} + {{ request.shop.name }}

-   View Shop +   View Shop

-   View Products +   View Products

-   View Coupons +   View Coupons

- 👤   Shop Users + 👤   Shop Users

- ⚙   Shop Settings + ⚙   Shop Settings {% if request.is_saas_domain %}
diff --git a/make_post_sell/templates/base.j2 b/make_post_sell/templates/base.j2 index 9731a74..c13bbc9 100644 --- a/make_post_sell/templates/base.j2 +++ b/make_post_sell/templates/base.j2 @@ -88,9 +88,7 @@
{% if request.is_saas_domain or request.user.can_edit_shop(request.shop) %} - {% if request.user.active_shop %} - ☰   {{ request.user.active_shop.name }} - {% endif %} + ☰   {{ request.shop.name }} {% endif %}
diff --git a/make_post_sell/templates/product_new.j2 b/make_post_sell/templates/product_new.j2 index 0196159..d12fe49 100644 --- a/make_post_sell/templates/product_new.j2 +++ b/make_post_sell/templates/product_new.j2 @@ -10,13 +10,13 @@

New Product


- Creating a new product in the shop named "{{ shop.name }}". + Creating a new product in the shop named "{{ request.shop.name }}".
- +
diff --git a/make_post_sell/views/coupon.py b/make_post_sell/views/coupon.py index 1348502..2bc3250 100644 --- a/make_post_sell/views/coupon.py +++ b/make_post_sell/views/coupon.py @@ -25,27 +25,17 @@ def get_coupon_from_matchdict(request): @view_config(route_name="coupons", renderer="coupons.j2") +@shop_owner_required def coupons(request): - - shop = request.user.active_shop - if request.shop: - shop = request.shop - - if request.user not in shop.users: - request.session.flash(("You do not own that Shop.", "error")) - return HTTPFound(get_referer_or_home(request)) - return { - "coupons": shop.coupons.all() + "coupons": request.shop.coupons.all() } @view_config(route_name="coupon1", renderer="coupon.j2") @view_config(route_name="coupon2", renderer="coupon.j2") def coupon(request): - coupon = get_coupon_from_matchdict(request) - return { "coupon": coupon } @@ -55,11 +45,6 @@ def coupon(request): @view_config(route_name="coupon_new2", renderer="coupon_new.j2") @shop_owner_required() def coupon_new(request): - - shop = request.user.active_shop - if request.shop: - shop = request.shop - code = request.params.get("code") description = request.params.get("description") action_type = request.params.get("action_type") @@ -76,7 +61,7 @@ def coupon_new(request): else: request.session.flash(("You created a new coupon!", "success")) coupon = Coupon( - shop = shop, + shop = request.shop, code = code, description = description, action_type = action_type, @@ -88,7 +73,7 @@ def coupon_new(request): ) request.dbsession.add(coupon) request.dbsession.flush() - return HTTPFound("/s/{}/coupons".format(shop.id)) + return HTTPFound("/s/{}/coupons".format(request.shop.id)) return request.params diff --git a/make_post_sell/views/product.py b/make_post_sell/views/product.py index 49ebade..fc09c46 100644 --- a/make_post_sell/views/product.py +++ b/make_post_sell/views/product.py @@ -86,10 +86,6 @@ def product(request): @shop_editor_required() def product_new(request): - shop = request.user.active_shop - if request.shop: - shop = request.shop - title = request.params.get("title", "") description = request.params.get("description", "") price = request.params.get("price", "") @@ -103,7 +99,7 @@ def product_new(request): if title and description: product = Product(title, description) - product.shop = shop + product.shop = request.shop product.is_bundle = is_bundle product.is_sellable = is_sellable @@ -126,7 +122,6 @@ def product_new(request): request.session.flash(msg) return { - "shop": shop, "title": title, "description": description, "price": price, diff --git a/make_post_sell/views/user.py b/make_post_sell/views/user.py index 8637c41..015eed2 100644 --- a/make_post_sell/views/user.py +++ b/make_post_sell/views/user.py @@ -23,7 +23,7 @@ def user_shops(request): @user_required() @shop_is_ready_required() def user_products(request): - # only display products for the currently active shop. + # only display products for the request's shop. products = [p for p in request.user.products if p.shop == request.shop] return { "products": products,