- {{ location.name }}
- {% if request.user.can_edit_shop(request.shop) %}
+ {{ location.name }}
+ {% if request.user and request.user.can_edit_shop(request.shop) %}
⚙ edit
{% endif %}
{% endfor %}
- {% if request.user.can_edit_shop(request.shop) %}
+ {% if request.user and request.user.can_edit_shop(request.shop) %}
Add New Location
{% endif %}
diff --git a/make_post_sell/views/shop_location.py b/make_post_sell/views/shop_location.py
index a2f3630..ba13ee5 100644
--- a/make_post_sell/views/shop_location.py
+++ b/make_post_sell/views/shop_location.py
@@ -171,21 +171,31 @@ def shop_locations(request):
"locations": request.shop.shop_locations,
}
+
@view_config(route_name="shop_location_switch")
def shop_location_switch(request):
shop_id = request.shop.id
location_id = request.matchdict.get("location_id")
+ next_url = request.params.get("next", request.route_url("shop", shop_id=shop_id))
# Fetch the location to ensure it exists and belongs to the shop
- location = request.dbsession.query(ShopLocation).filter_by(id=location_id, shop_id=shop_id).first()
+ location = (
+ request.dbsession.query(ShopLocation)
+ .filter_by(id=location_id, shop_id=shop_id)
+ .first()
+ )
if not location:
- request.session.flash(("Location not found or does not belong to this shop.", "error"))
+ request.session.flash(
+ ("Location not found or does not belong to this shop.", "error")
+ )
return HTTPFound(request.route_url("shop_locations", shop_id=shop_id))
# Update the session with the selected location
request.session["shop_location_id"] = str(location.id)
- request.session.flash((f"You are now viewing the {location.name} shop location", "success"))
+ request.session.flash(
+ (f"You are now viewing the {location.name} shop location", "success")
+ )
- # Redirect to the shop home page
- return HTTPFound(request.route_url("shop", shop_id=shop_id))
+ # Redirect to the next URL or the shop home page
+ return HTTPFound(next_url)