configure a default location if one or more!
modified: make_post_sell/request_methods.py
This commit is contained in:
parent
54317628e0
commit
0ead63ac58
1 changed files with 11 additions and 1 deletions
|
|
@ -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."""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue