Ejemplo n.º 1
0
    def __init__(self, descriptions, envts, cics, **kwargs):
        super(CIForm, self).__init__(**kwargs)
        iterator = ModelChoiceIterator(self.fields['description'])
        choices = [iterator.choice(obj) for obj in descriptions]
        choices.append(("", self.fields['description'].empty_label))
        self.fields['description'].choices = choices

        iterator = ModelChoiceIterator(self.fields['environments'])
        choices = [iterator.choice(obj) for obj in envts]
        self.fields['environments'].choices = choices

        iterator = ModelChoiceIterator(self.fields['instanciates'])
        choices = [iterator.choice(obj) for obj in cics]
        choices.append(("", self.fields['instanciates'].empty_label))
        self.fields['instanciates'].choices = choices
Ejemplo n.º 2
0
    def __init__(self, descriptions, envts, cics, **kwargs):
        super(CIForm, self).__init__(**kwargs)
        iterator = ModelChoiceIterator(self.fields['description'])
        choices = [iterator.choice(obj) for obj in descriptions]
        choices.append(("", self.fields['description'].empty_label))
        self.fields['description'].choices = choices

        iterator = ModelChoiceIterator(self.fields['environments'])
        choices = [iterator.choice(obj) for obj in envts]
        self.fields['environments'].choices = choices

        iterator = ModelChoiceIterator(self.fields['instanciates'])
        choices = [iterator.choice(obj) for obj in cics]
        choices.append(("", self.fields['instanciates'].empty_label))
        self.fields['instanciates'].choices = choices
Ejemplo n.º 3
0
 def __init__(self, *args, **kwargs):
     super(ModelMultipleChoiceFieldWithTitle,
           self).__init__(*args, **kwargs)
     iterator = ModelChoiceIterator(self)
     choices = [iterator.choice(obj) for obj in kwargs['queryset'].all()]
     choices.append(("", self.empty_label))
     self.choices = choices
Ejemplo n.º 4
0
 def limit_method_fields(self):
     basket = self.basket  # type: shoop.front.basket.objects.BaseBasket
     for field_name, methods in (
             ("shipping_method", basket.get_available_shipping_methods()),
             ("payment_method", basket.get_available_payment_methods()),
     ):
         field = self.fields[field_name]
         field.basket = self.basket
         mci = ModelChoiceIterator(field)
         field.choices = [mci.choice(obj) for obj in methods]
         if field.choices:
             field.initial = field.choices[0][0]
Ejemplo n.º 5
0
 def limit_method_fields(self):
     basket = self.basket  # type: shoop.front.basket.objects.BaseBasket
     for field_name, methods in (
             ("shipping_method", basket.get_available_shipping_methods()),
             ("payment_method", basket.get_available_payment_methods()),
     ):
         field = self.fields[field_name]
         field.basket = self.basket
         mci = ModelChoiceIterator(field)
         field.choices = [mci.choice(obj) for obj in methods]
         if field.choices:
             field.initial = field.choices[0][0]
Ejemplo n.º 6
0
    def __init__(self, cics, **kwargs):
        super(ReinitModelForm, self).__init__(**kwargs)

        iterator = ModelChoiceIterator(self.fields['instanciates'])
        choices = [iterator.choice(obj) for obj in cics]
        choices.append(("", self.fields['instanciates'].empty_label))
        self.fields['instanciates'].choices = choices

        if self.instance:
            # Stupid: self.instance can be overridden by a field named instance... So we store it inside another field (with a forbidden name)
            self.mage_instance = self.instance

            for field_instance in self.instance.rel_target_set.all():
                if field_instance.field.max_cardinality > 1:
                    continue
                self.fields[field_instance.field.name].initial = field_instance.target_id

            for field_instance in self.instance.field_set.all():
                self.fields[field_instance.field.name].initial = field_instance.value
Ejemplo n.º 7
0
    def __init__(self, cics, **kwargs):
        super(ReinitModelForm, self).__init__(**kwargs)

        iterator = ModelChoiceIterator(self.fields['instanciates'])
        choices = [iterator.choice(obj) for obj in cics]
        choices.append(("", self.fields['instanciates'].empty_label))
        self.fields['instanciates'].choices = choices

        if self.instance:
            # Stupid: self.instance can be overridden by a field named instance... So we store it inside another field (with a forbidden name)
            self.mage_instance = self.instance

            for field_instance in self.instance.rel_target_set.all():
                if field_instance.field.max_cardinality > 1:
                    continue
                self.fields[field_instance.field.
                            name].initial = field_instance.target_id

            for field_instance in self.instance.field_set.all():
                self.fields[
                    field_instance.field.name].initial = field_instance.value
Ejemplo n.º 8
0
 def __init__(self, *args, **kwargs):
     super(ModelChoiceFieldWithTitle, self).__init__(*args, **kwargs)
     iterator = ModelChoiceIterator(self)
     choices = [iterator.choice(obj) for obj in kwargs['queryset'].all()]
     choices.append(("", self.empty_label))
     self.choices = choices
Ejemplo n.º 9
0
 def __init__(self, cics, **kwargs):
     super(MiniModelForm, self).__init__(**kwargs)
     iterator = ModelChoiceIterator(self.fields['_instanciates'])
     choices = [iterator.choice(obj) for obj in cics]
     choices.append(("", self.fields['_instanciates'].empty_label))
     self.fields['_instanciates'].choices = choices
Ejemplo n.º 10
0
 def __init__(self, cics, **kwargs):
     super(MiniModelForm, self).__init__(**kwargs)
     iterator = ModelChoiceIterator(self.fields['_instanciates'])
     choices = [iterator.choice(obj) for obj in cics]
     choices.append(("", self.fields['_instanciates'].empty_label))
     self.fields['_instanciates'].choices = choices