def get_shop(self, request): if not request.user.is_staff: return None # take the first if multishop is disabled if not settings.SHUUP_ENABLE_MULTIPLE_SHOPS: return Shop.objects.first() permitted_shops = Shop.objects.get_for_user( request.user).filter(status=ShopStatus.ENABLED) if SHOP_SESSION_KEY in request.session: shop = Shop.objects.filter( pk=request.session[SHOP_SESSION_KEY]).first() if shop and shop in permitted_shops: return shop # try loading the shop from the host host = request.META.get("HTTP_HOST") shop = get_shop_from_host(host) if host else None if shop and shop in permitted_shops: return shop # no shop set, fetch the first shop available first_available_shop = permitted_shops.first() if first_available_shop: return first_available_shop # so return the first if we are superuser if request.user.is_superuser: return Shop.objects.first()
def get_shop(cls, request, **kwargs): shop = None host = request.META.get("HTTP_HOST") if host: shop = get_shop_from_host(host) if not shop: shop = Shop.objects.first() return shop
def get_shop(cls, request, **kwargs): shop = getattr(request, "_cached_default_shop_provider_shop", None) if shop: return shop host = request.META.get("HTTP_HOST") if host: shop = get_shop_from_host(host) if not shop: shop = Shop.objects.first() # cache shop as we already calculated it setattr(request, "_cached_default_shop_provider_shop", shop) return shop