def __call__(self, context, item, quantity=1, include_taxes=None, allow_cache=True): options = PriceDisplayOptions.from_context(context) if options.hide_prices: return "" if include_taxes is None: include_taxes = options.include_taxes request = context.get('request') price_info = get_cached_price_info( request, item, quantity, include_taxes=include_taxes) if allow_cache else None if not price_info: price_info = _get_priceful(request, item, quantity) if not price_info: return "" price_info = convert_taxness(request, item, price_info, include_taxes) if allow_cache: cache_price_info(request, item, quantity, price_info, include_taxes=include_taxes) return money(getattr(price_info, self.property_name))
def __call__(self, context, item, quantity=1, include_taxes=None, allow_cache=True): key, val = context_cache.get_cached_value( identifier=self.cache_identifier, item=item, context=context.get('request', context), quantity=quantity, include_taxes=include_taxes, name=self.name, allow_cache=allow_cache) if val is not None: return val options = PriceDisplayOptions.from_context(context) if options.hide_prices: context_cache.set_cached_value(key, "") return "" if include_taxes is None: include_taxes = options.include_taxes request = context.get('request') orig_priceful = _get_priceful(request, item, quantity) if not orig_priceful: context_cache.set_cached_value(key, "") return "" priceful = convert_taxness(request, item, orig_priceful, include_taxes) price_value = getattr(priceful, self.property_name) val = money(price_value) context_cache.set_cached_value(key, val) return val
def __call__(self, context, product, quantity=1, allow_cache=True): """ :type product: shuup.core.models.Product """ key, val = context_cache.get_cached_value( identifier=self.cache_identifier, item=product, context=context, quantity=quantity, name=self.name, allow_cache=allow_cache) if val is not None: return val options = PriceDisplayOptions.from_context(context) if options.hide_prices: val = ("", "") context_cache.set_cached_value(key, val) return val request = context.get('request') priced_children = product.get_priced_children(request, quantity) priced_products = priced_children if priced_children else [ (product, _get_priceful(request, product, quantity))] def get_formatted_price(priced_product): (prod, price_info) = priced_product if not price_info: return "" pf = convert_taxness(request, prod, price_info, options.include_taxes) price = money(pf.price) return price min_max = (priced_products[0], priced_products[-1]) prices = tuple(get_formatted_price(x) for x in min_max) context_cache.set_cached_value(key, prices) return prices
def __call__(self, context, item, quantity=1, include_taxes=None, allow_cache=True, supplier=None): options = PriceDisplayOptions.from_context(context) if options.hide_prices: return "" if include_taxes is None: include_taxes = options.include_taxes request = context.get('request') price_info = get_cached_price_info( request, item, quantity, include_taxes=include_taxes, supplier=supplier ) if allow_cache else None if not price_info: price_info = _get_priceful(request, item, quantity, supplier) if not price_info: return "" price_info = convert_taxness(request, item, price_info, include_taxes) if allow_cache: cache_price_info(request, item, quantity, price_info, include_taxes=include_taxes, supplier=supplier) return money(getattr(price_info, self.property_name))
def __call__(self, context, item, quantity=1, include_taxes=None, allow_cache=True): key, val = context_cache.get_cached_value( identifier=self.cache_identifier, item=item, context=context.get('request', context), quantity=quantity, include_taxes=include_taxes, name=self.name, allow_cache=allow_cache) if val is not None: return val options = PriceDisplayOptions.from_context(context) if options.hide_prices: context_cache.set_cached_value(key, "") return "" if include_taxes is None: include_taxes = options.include_taxes request = context.get('request') orig_priceful = _get_priceful(request, item, quantity) if not orig_priceful: context_cache.set_cached_value(key, "") return "" priceful = convert_taxness(request, item, orig_priceful, include_taxes) price_value = getattr(priceful, self.property_name) val = money(price_value) context_cache.set_cached_value(key, val) return val
def __call__(self, context, product, quantity=1, allow_cache=True): """ :type product: shuup.core.models.Product """ key, val = context_cache.get_cached_value( identifier=self.cache_identifier, item=product, context=context.get('request', context), quantity=quantity, name=self.name, allow_cache=allow_cache) if val is not None: return val options = PriceDisplayOptions.from_context(context) if options.hide_prices: val = ("", "") context_cache.set_cached_value(key, val) return val request = context.get('request') priced_children = product.get_priced_children(request, quantity) priced_products = priced_children if priced_children else [ (product, _get_priceful(request, product, quantity))] def get_formatted_price(priced_product): (prod, price_info) = priced_product if not price_info: return "" pf = convert_taxness(request, prod, price_info, options.include_taxes) price = money(pf.price) return price min_max = (priced_products[0], priced_products[-1]) prices = tuple(get_formatted_price(x) for x in min_max) context_cache.set_cached_value(key, prices) return prices
def __call__(self, context, product, quantity=1, allow_cache=True, supplier=None): """ :type product: shuup.core.models.Product """ options = PriceDisplayOptions.from_context(context) if options.hide_prices: return ("", "") request = context.get('request') priced_products = get_many_cached_price_info( request, product, quantity, include_taxes=options.include_taxes, supplier=supplier) if allow_cache else None if not priced_products: priced_children_key = PRICED_CHILDREN_CACHE_KEY % (product.id, quantity) priced_products = [] if hasattr(request, priced_children_key): priced_children = getattr(request, priced_children_key) else: priced_children = product.get_priced_children( request, quantity) or [ (product, _get_priceful(request, product, quantity, supplier)) ] setattr(request, priced_children_key, priced_children) for child_product, price_info in priced_children: if not price_info: continue priceful = convert_taxness(request, child_product, price_info, options.include_taxes) priced_products.append(priceful) if priced_products and allow_cache: cache_many_price_info(request, product, quantity, priced_products, include_taxes=options.include_taxes, supplier=supplier) if not priced_products: return ("", "") return (money(priced_products[0].price), money(priced_products[-1].price))
def __call__(self, context, item, quantity=1): options = PriceDisplayOptions.from_context(context) if options.hide_prices: return "" request = context.get('request') orig_priceful = _get_priceful(request, item, quantity) if not orig_priceful: return "" priceful = convert_taxness( request, item, orig_priceful, options.include_taxes) price_value = getattr(priceful, self.property_name) return money(price_value)
def __call__(self, context, item, quantity=1): options = PriceDisplayOptions.from_context(context) if options.hide_prices: return "" request = context.get('request') orig_priceful = _get_priceful(request, item, quantity) if not orig_priceful: return "" priceful = convert_taxness(request, item, orig_priceful, options.include_taxes) price_value = getattr(priceful, self.property_name) return money(price_value)
def __call__(self, context, product, quantity=1, allow_cache=True, supplier=None): """ :type product: shuup.core.models.Product """ options = PriceDisplayOptions.from_context(context) if options.hide_prices: return ("", "") request = context.get('request') priced_products = get_many_cached_price_info( request, product, quantity, include_taxes=options.include_taxes, supplier=supplier ) if allow_cache else None if not priced_products: priced_children_key = PRICED_CHILDREN_CACHE_KEY % (product.id, quantity) priced_products = [] if hasattr(request, priced_children_key): priced_children = getattr(request, priced_children_key) else: priced_children = product.get_priced_children(request, quantity) or [ (product, _get_priceful(request, product, quantity, supplier)) ] setattr(request, priced_children_key, priced_children) for child_product, price_info in priced_children: if not price_info: continue priceful = convert_taxness(request, child_product, price_info, options.include_taxes) priced_products.append(priceful) if priced_products and allow_cache: cache_many_price_info( request, product, quantity, priced_products, include_taxes=options.include_taxes, supplier=supplier) if not priced_products: return ("", "") return (money(priced_products[0].price), money(priced_products[-1].price))
def render_price_property(request, item, priceful, property_name='price'): """ Render price property of a Priceful object. :type request: django.http.HttpRequest :type item: shuup.core.taxing.TaxableItem :type priceful: shuup.core.pricing.Priceful :type propert_name: str :rtype: str """ options = PriceDisplayOptions.from_context({'request': request}) if options.hide_prices: return "" new_priceful = convert_taxness(request, item, priceful, options.include_taxes) price_value = getattr(new_priceful, property_name) return money(price_value)
def render_price_property(request, item, priceful, property_name='price'): """ Render price property of a Priceful object. :type request: django.http.HttpRequest :type item: shuup.core.taxing.TaxableItem :type priceful: shuup.core.pricing.Priceful :type propert_name: str :rtype: str """ options = PriceDisplayOptions.from_context({'request': request}) if options.hide_prices: return "" new_priceful = convert_taxness( request, item, priceful, options.include_taxes) price_value = getattr(new_priceful, property_name) return money(price_value)
def __call__(self, context, source): """ :type source: shuup.core.order_creator.OrderSource| shuup.core.models.Order """ options = PriceDisplayOptions.from_context(context) if options.hide_prices: return "" try: if options.include_taxes is None: total = source.total_price elif options.include_taxes: total = source.taxful_total_price else: total = source.taxless_total_price except TypeError: total = source.total_price return money(total)
def __call__(self, context, source): """ :type source: shuup.core.order_creator.OrderSource| shuup.core.models.Order """ options = PriceDisplayOptions.from_context(context) if options.hide_prices: return "" try: if options.include_taxes is None: total = source.total_price elif options.include_taxes: total = source.taxful_total_price else: total = source.taxless_total_price except TypeError: total = source.total_price return money(total)
def __call__(self, context, product, quantity=1): """ :type product: shuup.core.models.Product """ options = PriceDisplayOptions.from_context(context) if options.hide_prices: return ("", "") request = context.get('request') priced_children = product.get_priced_children(request, quantity) priced_products = priced_children if priced_children else [ (product, _get_priceful(request, product, quantity))] def get_formatted_price(priced_product): (prod, price_info) = priced_product if not price_info: return "" pf = convert_taxness( request, prod, price_info, options.include_taxes) return money(pf.price) min_max = (priced_products[0], priced_products[-1]) return tuple(get_formatted_price(x) for x in min_max)
def __call__(self, context, product, quantity=1): """ :type product: shuup.core.models.Product """ options = PriceDisplayOptions.from_context(context) if options.hide_prices: return ("", "") request = context.get('request') priced_children = product.get_priced_children(request, quantity) priced_products = priced_children if priced_children else [ (product, _get_priceful(request, product, quantity)) ] def get_formatted_price(priced_product): (prod, price_info) = priced_product if not price_info: return "" pf = convert_taxness(request, prod, price_info, options.include_taxes) return money(pf.price) min_max = (priced_products[0], priced_products[-1]) return tuple(get_formatted_price(x) for x in min_max)