Пример #1
0
 def clean(self):
     if self.file:
         if self.file.extension not in self.EXTENSIONS[self.kind]:
             raise ValidationError('%s (%s)' %
                                   (em('wrong_extension'), ', '.join(
                                       self.EXTENSIONS[self.kind])))
     elif not self.url:
         raise ValidationError(em('no_attachment_or_url'))
Пример #2
0
 def clean_available_attributes(self):
     attrs = self.cleaned_data.get('available_attributes')
     kind = self.cleaned_data.get('kind')
     if kind != Product.GROUP and attrs:
         raise forms.ValidationError(
             em('not_group_has_available_attributes'))
     elif kind == Product.GROUP and not attrs:
         raise forms.ValidationError(em('group_no_available_attributes'))
     return attrs
Пример #3
0
 def _clean_variant(self):
     if self._category_id or self._brand_id or self._manufacturer_id:
         raise ValidationError(em('variant_has_category'))
     if self._tax_id:
         raise ValidationError(em('variant_has_tax'))
     if not self.group_id:
         raise ValidationError(em('variant_no_group'))
     if self.group.is_variant:
         raise ValidationError(em('varinat_group_variant'))
     if self.variants.exists():
         raise ValidationError(em('not_group_has_variants'))
Пример #4
0
 def clean_group(self):
     group = self.cleaned_data.get('group')
     kind = self.cleaned_data.get('kind')
     if group is None:
         if kind == Product.VARIANT:
             raise forms.ValidationError(em('variant_no_group'))
     else:
         if kind != Product.VARIANT:
             raise forms.ValidationError(em('group_has_group'))
         if group.is_variant:
             raise forms.ValidationError(em('varinat_group_variant'))
     return group
Пример #5
0
 def clean_code(self):
     code = self.cleaned_data.get('code', None)
     if code:
         cart_codes = self.cart.get_discount_codes().values_list('code',
                                                                 flat=True)
         if code in cart_codes:
             raise forms.ValidationError(em('cart_discount_code_exists'))
         try:
             dc = DiscountCode.objects.valid().get(code=code)
         except DiscountCode.DoesNotExist:
             raise forms.ValidationError(em('cart_discount_code_invalid'))
         if dc.customer and code not in self.cart.customer.get_discount_codes(
         ).values_list('code', flat=True):
             raise forms.ValidationError(
                 em('cart_discount_code_wrong_customer'))
         self._discount_code = dc
     return code
Пример #6
0
 def clean_slug(self):
     slug = self.cleaned_data.get('slug')
     queryset = Product.objects.translated(slug=slug)
     if self.instance.pk is not None:
         queryset = queryset.exclude(pk=self.instance.pk)
     if queryset.exists():
         raise forms.ValidationError(em('duplicate_slug'))
     return slug
Пример #7
0
    def clean(self):
        super(AttributeChoiceInlineFormSet, self).clean()
        instance = getattr(self, 'instance', None)

        if any(self.errors) or instance is None:
            return

        clean_forms = [
            x for x in self.forms
            if 'value' in x.cleaned_data and not x.cleaned_data['DELETE']
        ]
        if not clean_forms:
            raise forms.ValidationError(em('attribute_no_choices'))

        clean_values = [x.cleaned_data['value'] for x in clean_forms]
        if len(clean_values) != len(set(clean_values)):
            raise forms.ValidationError(em('attribute_duplicate_choices'))
Пример #8
0
    def clean_choice(self):
        choice = self.cleaned_data.get('choice')
        attribute = self.cleaned_data.get('attribute')

        # Make sure correct choice is selected for the attribute.
        if attribute and not attribute.nullable:
            if choice not in attribute.get_choices():
                raise forms.ValidationError(em('incorrect_attribute_choice'))
        return choice
Пример #9
0
    def clean(self):
        super(AttributeValueInlineFormSet, self).clean()
        instance = getattr(self, 'instance', None)

        if any(self.errors) or instance is None:
            return

        clean_forms = [
            x for x in self.forms
            if 'attribute' in x.cleaned_data and not x.cleaned_data['DELETE']
        ]

        if instance.is_variant:
            if not clean_forms:
                raise forms.ValidationError(em('variant_no_attributes'))
            elif self.variant_exists(instance, clean_forms):
                raise forms.ValidationError(em('variant_already_exists'))
        elif clean_forms:
            raise forms.ValidationError(em('not_variant_has_attributes'))
Пример #10
0
 def clean(self):
     if self.base.is_variant or self.product.is_variant:
         raise ValidationError(em('variant_has_relations'))
     if self.base == self.product:
         raise ValidationError(em('relation_base_is_product'))
Пример #11
0
 def clean__tax(self):
     tax = self.cleaned_data.get('_tax')
     kind = self.cleaned_data.get('kind')
     if kind == Product.VARIANT and tax is not None:
         raise forms.ValidationError(em('variant_has_tax'))
     return tax
Пример #12
0
 def clean_kind(self):
     kind = self.cleaned_data.get('kind')
     if kind != Product.GROUP:
         if self.instance.variants.exists():
             raise forms.ValidationError(em('not_group_has_variants'))
     return kind
Пример #13
0
 def _clean_group(self):
     if self.group_id:
         raise ValidationError(em('group_has_group'))
Пример #14
0
 def _clean_single(self):
     if self.group_id:
         raise ValidationError(em('group_has_group'))
     if self.variants.exists():
         raise ValidationError(em('not_group_has_variants'))
Пример #15
0
 def _clean_categorization(self, name):
     data = self.cleaned_data.get(name, None)
     kind = self.cleaned_data.get('kind')
     if data and kind == Product.VARIANT:
         raise forms.ValidationError(em('variant_has_category'))
     return data
Пример #16
0
 def clean(self):
     if not self.path:
         raise ValidationError(em('modifier_no_condition_path'))
Пример #17
0
 def clean(self):
     if self.kind == self.DISCOUNT:
         if self.percent and self.percent >= 0 or not self.percent and self.amount >= 0:
             raise ValidationError(em('discount_not_negative'))