def start_listening(): variant_formclass_for_product.connect(get_cardiganvariant_formclass, sender=models.Cardigan) variant_formclass_for_product.connect(get_dressvariant_formclass, sender=models.Dress) variant_formclass_for_product.connect(get_hatvariant_formclass, sender=models.Hat) variant_formclass_for_product.connect(get_jacketvariant_formclass, sender=models.Jacket) variant_formclass_for_product.connect(get_shirtvariant_formclass, sender=models.Shirt) variant_formclass_for_product.connect(get_tshirtvariant_formclass, sender=models.TShirt) variant_formclass_for_product.connect(get_trousersvariant_formclass, sender=models.Trousers)
color=self.cleaned_data['color'], looks_alive=self.cleaned_data['looks_alive']) def clean(self): if not self._get_variant_queryset().exists(): raise forms.ValidationError("Variant does not exist") return self.cleaned_data def get_variant(self): return self._get_variant_queryset().get() def get_variantformclass(sender=None, instance=None, formclass=None, **kwargs): formclass.append(DeadParrotVariantForm) variant_formclass_for_product.connect(get_variantformclass, sender=DeadParrot) class ParrotTest(TestCase): def setUp(self): category = Category.objects.create(name='parrot') self.macaw = DeadParrot.objects.create(slug='macaw', species="Hyacinth Macaw") self.macaw.categories.add(category) self.cockatoo = DeadParrot.objects.create(slug='cockatoo', species="White Cockatoo") self.cockatoo.categories.add(category) self.macaw_blue = self.macaw.variants.create(color='blue', looks_alive=False) self.macaw_blue_fake = self.macaw.variants.create(color='blue', looks_alive=True) self.cockatoo_white_a = self.cockatoo.variants.create(color='white', looks_alive=True) self.cockatoo_white_d = self.cockatoo.variants.create(color='white', looks_alive=False)
looks_alive=self.cleaned_data['looks_alive']) def clean(self): if not self._get_variant_queryset().exists(): raise forms.ValidationError("Variant does not exist") return self.cleaned_data def get_variant(self): return self._get_variant_queryset().get() def get_variantformclass(sender=None, instance=None, formclass=None, **kwargs): formclass.append(DeadParrotVariantForm) variant_formclass_for_product.connect(get_variantformclass, sender=DeadParrot) class ParrotTest(TestCase): def setUp(self): category = Category.objects.create(name='parrot') self.macaw = DeadParrot.objects.create(slug='macaw', species="Hyacinth Macaw") self.macaw.categories.add(category) self.cockatoo = DeadParrot.objects.create(slug='cockatoo', species="White Cockatoo") self.cockatoo.categories.add(category) self.macaw_blue = self.macaw.variants.create(color='blue', looks_alive=False) self.macaw_blue_fake = self.macaw.variants.create(color='blue', looks_alive=True)
def start_listening(): variant_formclass_for_product.connect(get_variant_formclass, sender=models.Dummy)
def start_listening(): variant_formclass_for_product.connect(get_collarsvariant_formclass, sender=models.Collars) variant_formclass_for_product.connect(get_collarswithleashvariant_formclass, sender=models.CollarsWithLeash) variant_formclass_for_product.connect(get_raincoatvariant_formclass, sender=models.Raincoat) variant_formclass_for_product.connect(get_transportbagvariant_formclass, sender=models.TransportBag) variant_formclass_for_product.connect(get_harnessvariant_formclass, sender=models.Harness) variant_formclass_for_product.connect(get_clothingvariant_formclass, sender=models.Clothing) variant_formclass_for_product.connect(get_scarvesvariant_formclass, sender=models.Scarves) variant_formclass_for_product.connect(get_bedsvariant_formclass, sender=models.Beds)
from satchless.product.signals import variant_formclass_for_product from . import models from . import forms def get_variant_formclass(sender=None, instance=None, formclass=[], **kwargs): formclass.append(forms.DummyVariantForm) variant_formclass_for_product.connect(get_variant_formclass, sender=models.Dummy)
from satchless.product.signals import variant_formclass_for_product from . import forms from . import models def get_variantformclass(sender=None, instance=None, formclass=None, **kwargs): formclass.append(forms.ParrotVariantForm) variant_formclass_for_product.connect(get_variantformclass, sender=models.Parrot)