def variation_choice(cls, variation, attributes=None, **kwargs): result = (yield chaining.forward).result if result is not None: return variant = variation.variant.downcast() price_adjustment = None if variant.is_variant: a = Price.calculate(product=variant, raw=True) b = Price.calculate(product=variant.product, raw=True) price_adjustment = Price(0) if a is not None and b is not None: price_adjustment = (a - b) values = variation.values.all().order_by('attribute') if attributes is not None: values = values.filter(attribute__in=attributes) values = VARIATION_VALUE_SEPERATOR.join( [unicode(value) for value in values] ) yield call_or_format( VARIATION_CHOICE_FORMAT, variation=variation, variant=variant, values=values, price_adjustment=price_adjustment )
def variation_choice(cls, variation, attributes=None, **kwargs): result = (yield chaining.forward).result if result is not None: return variant = variation.variant.downcast() price_adjustment = None if variant.is_variant: a = Price.calculate(product=variant, raw=True) b = Price.calculate(product=variant.product, raw=True) price_adjustment = Price(0) if a is not None and b is not None: price_adjustment = (a - b) values = variation.values.all().order_by('attribute') if attributes is not None: values = values.filter(attribute__in=attributes) values = VARIATION_VALUE_SEPERATOR.join( [unicode(value) for value in values]) yield call_or_format(VARIATION_CHOICE_FORMAT, variation=variation, variant=variant, values=values, price_adjustment=price_adjustment)
def __unicode__(self): # Do not simply supply value=self, this would encourage recursive calls to # __unicode__ return call_or_format( VALUE_FORMAT, value=self.value, attribute=self.attribute )
def values_description(values, prefix=None): values = VARIATION_VALUE_SEPERATOR.join( [unicode(value) for value in values]) return call_or_format(VARIATION_DESCRIPTION_FORMAT, prefix=prefix, values=values)
def format(self, amount, align=-1): return call_or_format(self._frmt, amount=amount, align=align)
def __unicode__(self): # Do not simply supply value=self, this would encourage recursive calls to # __unicode__ return call_or_format(VALUE_FORMAT, value=self.value, attribute=self.attribute)
def values_description(values, prefix=None): values = VARIATION_VALUE_SEPERATOR.join([unicode(value) for value in values]) return call_or_format(VARIATION_DESCRIPTION_FORMAT, prefix=prefix, values=values)