Example #1
0
    def _create_parent_product_fields(self, product):
        """
        Adds the fields for a "group"-type product (eg, a parent product with a
        list of children.

        Currently requires that a stock record exists for the children
        """
        choices = []
        disabled_values = []
        for child in product.children.all():
            # Build a description of the child, including any pertinent
            # attributes
            attr_summary = child.attribute_summary
            if attr_summary:
                summary = attr_summary
            else:
                summary = child.get_title()

            # Check if it is available to buy
            info = self.basket.strategy.fetch_for_product(child)
            if not info.availability.is_available_to_buy:
                disabled_values.append(child.id)

            choices.append((child.id, summary))

        self.fields['child_id'] = forms.ChoiceField(
            choices=tuple(choices),
            label=_("Variant"),
            widget=widgets.AdvancedSelect(disabled_values=disabled_values))
Example #2
0
    def test_widget_disabled_options(self):

        choices = (
            ('red', 'Red'),
            ('blue', 'Blue'),
            ('green', 'Green'),
        )

        disabled_values = ('red', 'green')

        i = widgets.AdvancedSelect(choices=choices, disabled_values=disabled_values)
        html = i.render('advselect', [])
        self.assertInHTML('<option value="blue">Blue</option>', html, count=1)
        self.assertInHTML('<option value="red" disabled>Red</option>', html, count=1)
        self.assertInHTML('<option value="green" disabled>Green</option>', html, count=1)
Example #3
0
 def _create_parent_product_fields(self, product):
     """
     Adds the fields for a "group"-type product (eg, a parent product with a
     list of children.
     Currently requires that a stock record exists for the children
     """
     choices = []
     disabled_values = []
     child_products = []
     if product.is_parent:
         child_products = product.children.all()
     elif product.is_child:
         child_products = product.parent.children.all()
     for child in child_products:
         summary = child.get_title_for_dropdown
         choices.append((child.get_absolute_url(), summary))
     self.fields['child_id'] = forms.ChoiceField(
         choices=tuple(choices),
         label=_("Variant"),
         widget=widgets.AdvancedSelect(disabled_values=disabled_values))
Example #4
0
    def _create_group_product_fields(self, item):
        """
        Adds the fields for a "group"-type product (eg, a parent product with a
        list of variants.

        Currently requires that a stock record exists for the variant
        """
        choices = []
        disabled_values = []
        for variant in item.variants.all():
            attr_summary = variant.attribute_summary
            if attr_summary:
                summary = attr_summary
            else:
                summary = variant.get_title()
            info = self.request.strategy.fetch_for_product(variant)
            if not info.availability.is_available_to_buy:
                disabled_values.append(variant.id)
            choices.append((variant.id, summary))

        self.fields['product_id'] = forms.ChoiceField(
            choices=tuple(choices),
            label=_("Variant"),
            widget=widgets.AdvancedSelect(disabled_values=disabled_values))