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
This commit is contained in:
Russell Ballestrini 2022-07-07 11:53:56 -04:00
parent 3893437dc8
commit 7f1ec29786
7 changed files with 18 additions and 40 deletions

View file

@ -4,9 +4,9 @@
<section class="one-column well">
{% if request.user.active_shop %}
{% if request.shop %}
<b>{{ request.user.active_shop.name }}</b>
<b>{{ request.shop.name }}</b>
<br/>
<br/>

View file

@ -4,29 +4,29 @@
<section class="one-column well">
{% if request.user.active_shop %}
{% if request.shop %}
<b>{{ request.user.active_shop.name }}</b>
<b>{{ request.shop.name }}</b>
<br/>
<br/>
<a href="/s/{{ request.user.active_shop.id }}/{{ request.user.active_shop.slug }}" class="product-edit-button mps-button">&nbsp View Shop</a>
<a href="/s/{{ request.shop.id }}/{{ request.shop.slug }}" class="product-edit-button mps-button">&nbsp View Shop</a>
<br/>
<br/>
<a href="/s/{{ request.user.active_shop.id }}/products" class="product-edit-button mps-button">&nbsp View Products</a>
<a href="/s/{{ request.shop.id }}/products" class="product-edit-button mps-button">&nbsp View Products</a>
<br/>
<br/>
<a href="/s/{{ request.user.active_shop.id }}/coupons" class="product-edit-button mps-button">&nbsp View Coupons</a>
<a href="/s/{{ request.shop.id }}/coupons" class="product-edit-button mps-button">&nbsp View Coupons</a>
<br/>
<br/>
<a href="/s/{{ request.user.active_shop.id }}/users" class="product-edit-button mps-button">&#128100; &nbsp Shop Users</a>
<a href="/s/{{ request.shop.id }}/users" class="product-edit-button mps-button">&#128100; &nbsp Shop Users</a>
<br/>
<br/>
<a href="/s/{{ request.user.active_shop.id }}/settings" class="product-edit-button mps-button">&#9881; &nbsp Shop Settings</a>
<a href="/s/{{ request.shop.id }}/settings" class="product-edit-button mps-button">&#9881; &nbsp Shop Settings</a>
{% if request.is_saas_domain %}
<br/>

View file

@ -88,9 +88,7 @@
<section class="windows-95-start-button">
{% if request.is_saas_domain or request.user.can_edit_shop(request.shop) %}
{% if request.user.active_shop %}
<a href="/actions/view" class="windows-95-start-button mps-button mps-button-blue"><span style="font-size: 20px;">&#9776; &nbsp </span> {{ request.user.active_shop.name }}</a>
{% endif %}
<a href="/actions/view" class="windows-95-start-button mps-button mps-button-blue"><span style="font-size: 20px;">&#9776; &nbsp </span> {{ request.shop.name }}</a>
{% endif %}
</section>

View file

@ -10,13 +10,13 @@
<h3>New Product</h3>
<br/>
Creating a new product in the shop named "{{ shop.name }}".
Creating a new product in the shop named "{{ request.shop.name }}".
<br/>
<form method="post" action="/p/new" onsubmit="submit.disabled = true; return true;">
<input type="hidden" name="shop_id" value="{{ shop.id }}" />
<input type="hidden" name="shop_id" value="{{ request.shop.id }}" />
<br/>
<label for="title_input">Product Title</label>

View file

@ -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

View file

@ -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,

View file

@ -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,