Esempio n. 1
0
    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
        )
Esempio n. 2
0
    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)
Esempio n. 3
0
 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
     )
Esempio n. 4
0
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)
Esempio n. 5
0
 def format(self, amount, align=-1):
     return call_or_format(self._frmt, amount=amount, align=align)
Esempio n. 6
0
 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)
Esempio n. 7
0
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)