def en_percent(num, ndigits="not-given"): """ Format given number as percent in en-US locale. """ with translation.override("en-US"): if ndigits == "not-given": return percent(Decimal(num)) else: return percent(Decimal(num), ndigits)
def en_percent(num, ndigits="not-given"): """ Format given number as percent in en-US locale. """ with translation.override("en-US"): if ndigits == "not-given": return percent(Decimal(num)) else: return percent(Decimal(num), ndigits)
def __call__(self, context, item, quantity=1, allow_cache=True, supplier=None): request = context.get("request") price_info = get_cached_price_info( request, item, quantity, supplier=supplier) if allow_cache else None if not price_info: price_info = _get_item_price_info(request, item, quantity, supplier) if not price_info: return "" if allow_cache: cache_price_info(request, item, quantity, price_info, supplier=supplier) return percent(getattr(price_info, self.property_name))
def __call__(self, context, item, quantity=1, allow_cache=True, supplier=None): request = context.get('request') price_info = get_cached_price_info(request, item, quantity, supplier=supplier) if allow_cache else None if not price_info: price_info = _get_priceful(request, item, quantity, supplier) if not price_info: return "" if allow_cache: cache_price_info(request, item, quantity, price_info, supplier=supplier) return percent(getattr(price_info, self.property_name))
def __call__(self, context, item, quantity=1, allow_cache=True): request = context.get('request') price_info = get_cached_price_info(request, item, quantity) if allow_cache else None if not price_info: price_info = _get_priceful(request, item, quantity) if not price_info: return "" if allow_cache: cache_price_info(request, item, quantity, price_info) return percent(getattr(price_info, self.property_name))
def __call__(self, context, item, quantity=1, allow_cache=True): key, val = context_cache.get_cached_value( identifier=self.cache_identifier, item=item, context=context.get('request', context), quantity=quantity, name=self.name, allow_cache=allow_cache) if val is not None: return val priceful = _get_priceful(context.get('request'), item, quantity) if not priceful: context_cache.set_cached_value(key, "") return "" val = percent(getattr(priceful, self.property_name)) context_cache.set_cached_value(key, val) return val
def __call__(self, context, item, quantity=1, allow_cache=True): key, val = context_cache.get_cached_value( identifier=self.cache_identifier, item=item, context=context.get('request', context), quantity=quantity, name=self.name, allow_cache=allow_cache) if val is not None: return val priceful = _get_priceful(context.get('request'), item, quantity) if not priceful: context_cache.set_cached_value(key, "") return "" val = percent(getattr(priceful, self.property_name)) context_cache.set_cached_value(key, val) return val
def test_number_formatters_fi(): with translation.override("fi-FI"): assert percent(Decimal("0.38")) == nbsp("38 %") assert number(Decimal("38.00000")) == "38" assert number(Decimal("38.05000")) == "38,05"
def test_number_formatters_en(): with translation.override("en-US"): assert percent(Decimal("0.38")) == "38%" assert number(Decimal("38.00000")) == "38" assert number(Decimal("38.05000")) == "38.05"
def test_number_formatters_fi(): with translation.override("fi-FI"): assert percent(Decimal("0.38")) == nbsp("38 %") assert number(Decimal("38.00000")) == "38" assert number(Decimal("38.05000")) == "38,05"
def test_number_formatters_en(): with translation.override("en-US"): assert percent(Decimal("0.38")) == "38%" assert number(Decimal("38.00000")) == "38" assert number(Decimal("38.05000")) == "38.05"
def __call__(self, context, item, quantity=1): priceful = _get_priceful(context.get('request'), item, quantity) if not priceful: return "" return percent(getattr(priceful, self.property_name))
def __call__(self, context, item, quantity=1): priceful = _get_priceful(context.get('request'), item, quantity) if not priceful: return "" return percent(getattr(priceful, self.property_name))