configure a default location if one or more!

modified:   make_post_sell/request_methods.py
This commit is contained in:
Russell Ballestrini 2024-12-06 07:48:39 -05:00
parent 54317628e0
commit 0ead63ac58

View file

@ -85,10 +85,20 @@ def includeme(config):
return cart
def add_shop_location(request):
"""Return ShopLocation from session or None."""
"""
Return the ShopLocation from session if available.
If not, and the shop has one or more locations, set the first location as the default.
Returns None if no locations are available.
"""
shop_location_id = request.session.get("shop_location_id")
if shop_location_id is not None:
return get_shop_location_by_id(request.dbsession, shop_location_id)
if request.shop:
first_location = request.shop.shop_locations.first()
if first_location:
request.session["shop_location_id"] = str(first_location.id)
return first_location
return None
def add_market(request):
"""Return Market object or None."""