コード例 #1
0
class CasaForm(utils.BaseFormAllFields):
    title = 'Casa'
    numero_manzana = forms.ModelChoiceField(
        queryset=models.Manzana.objects.all(), widget=Select2())

    class Meta(utils.BaseFormAllFields.Meta):
        model = models.Casa
コード例 #2
0
ファイル: purchase.py プロジェクト: ryanbagwell/repanier
 class Meta:
     model = Purchase
     fields = "__all__"
     widgets = {
         # 'permanence': SelectAdminPermanenceWidget(),
         "customer": Select2(select2attrs={"width": "450px"})
     }
コード例 #3
0
class ProdoptForm(ModelForm):
    defaultchoice = ModelChoiceField(
        Choice.objects.published(),
        widget=Select2(select2attrs={'width': '350px'}))

    def __init__(self, *args, **kw):
        ModelForm.__init__(self, *args, **kw)

        #self.fields ['choices'].queryset = Choice.objects.published()  # so only published appear in slider
        cf = self.fields.get('choices', '')
        if cf:
            cf.queryset = Choice.objects.published(
            )  # so only published appear in slider

        if self.instance and isinstance(self.instance, Prodopt):
            inst = self.instance
            dc = self.fields.get('defaultchoice')
            if trace: print inst.all_choices  # option_id # dir (inst)
            if inst.pk and inst.all_choices().count():
                dc.queryset = inst.all_choices(
                )  #Choice.objects.filter (id__in = inst.choices.values_list('id', flat=True))
                # nope: they are blank:
                #if inst.all_choices().count() >5:
                #  dc.widget = Select2(select2attrs={'width': '350px'})

    class Meta:
        model = Prodopt
        fields = '__all__'
コード例 #4
0
 class Meta:
     model = Purchase
     fields = "__all__"
     widgets = {
         'permanence': SelectAdminPermanenceWidget(),
         'customer': Select2(select2attrs={'width': '450px'})
     }
コード例 #5
0
 class Meta:
     model = Menu
     fields = '__all__'
     exclude = ('name',)
     widgets = {
         'parent': Select2()
     }
コード例 #6
0
class QuestionForm(forms.ModelForm):
    categorie = forms.ModelChoiceField(
        queryset=Categorie.objects.all(),
        widget=Select2(select2attrs={'width': '100%'}))

    class Meta:
        model = Question
        fields = ['question_text']
コード例 #7
0
ファイル: purchase.py プロジェクト: jaliste/repanier
class PurchaseForm(forms.ModelForm):
    product = forms.ChoiceField(
        label=_("Product"), widget=Select2(select2attrs={"width": "450px"}))
    delivery = forms.ChoiceField(label=_("Delivery point"),
                                 widget=SelectAdminDeliveryWidget())
    quantity = forms.DecimalField(
        min_value=DECIMAL_ZERO,
        label=_("Qty"),
        max_digits=9,
        decimal_places=4,
        required=True,
        initial=0,
    )

    def __init__(self, *args, **kwargs):
        super(PurchaseForm, self).__init__(*args, **kwargs)
        purchase = self.instance
        if purchase.id is not None:
            if purchase.status < PERMANENCE_SEND:
                self.fields["quantity"].initial = purchase.quantity_ordered
            else:
                self.fields["quantity"].initial = purchase.quantity_invoiced

    def clean_product(self):
        product_id = sint(self.cleaned_data.get("product"), 0)
        if product_id <= 0:
            if product_id == -1:
                self.add_error(
                    "product",
                    _("Please select first a producer in the filter of previous screen"
                      ),
                )
            else:
                self.add_error(
                    "product",
                    _("No more product to add. Please update a product of previous screen"
                      ),
                )
        return product_id

    def clean(self):
        if any(self.errors):
            # Don't bother validating the formset unless each form is valid on its own
            return
        if self.instance.id is None:
            quantity = self.cleaned_data.get("quantity", DECIMAL_ZERO)
            if quantity == DECIMAL_ZERO:
                self.add_error("quantity",
                               _("The quantity must be different than zero."))
        # self._validate_unique = False

    class Meta:
        model = Purchase
        fields = "__all__"
        widgets = {
            # 'permanence': SelectAdminPermanenceWidget(),
            "customer": Select2(select2attrs={"width": "450px"})
        }
コード例 #8
0
class CCatForm(ModelForm):
    parent = ModelChoiceField(ChoiceCategory.objects.published(),
                              widget=Select2(),
                              required=False)

    choices = ModelMultipleChoiceField(
        Choice.objects.published(),
        # Add this line to use the double list widget
        widget=FilteredSelectMultiple('Choices', False),
        required=False,
    )

    def __init__(self, *args, **kwargs):
        super(CCatForm, self).__init__(*args, **kwargs)
        #ModelForm.__init__ (self, *args, **kwargs)
        #print 'instance:', self.instance
        #if self.instance and isinstance (self.instance, Category):
        #  inst=self.instance
        #  dc=self.fields.get('defaultchoice')
        #  if trace: print inst.all_choices # option_id # dir (inst)
        #  if inst.pk and inst.all_choices().count():
        #    dc.queryset = inst.all_choices()  #Choice.objects.filter (id__in = inst.choices.values_list('id', flat=True))
        if self.instance.pk:
            # if this is not a new object, we load related books
            self.initial['choices'] = self.instance.choice_set.values_list(
                'pk', flat=True)
            #rel = ManyToManyRel(Choice)
            #self.fields['choice'].widget = RelatedFieldWidgetWrapper(self.fields['choice'].widget, rel, admin.site)

    def save(self, *args, **kwargs):
        instance = super(CCatForm, self).save(*args, **kwargs)

        if instance.pk:
            for choice in instance.choice_set.all():
                if choice not in self.cleaned_data['choices']:
                    # we remove choice which has been unselected
                    # m2m:
                    #instance.choice_set.remove(choice)
                    # fk:
                    choice.choicecategory = get_misc_choice_category(
                    )  # set to Misc - 43882 :)
                    choice.save()

            for choice in self.cleaned_data['choices']:
                if choice not in instance.choice_set.all():
                    # we add newly selected choice
                    # m2m:
                    #instance.choice_set.add(choice)
                    # fk:
                    choice.choicecategory = instance
                    choice.save()

        return instance
コード例 #9
0
class MenuAdminForm(forms.ModelForm):
    view = forms.ChoiceField(label=_('View'), required=False, widget=Select2())

    def __init__(self, *args, **kwargs):
        super(MenuAdminForm, self).__init__(*args, **kwargs)

        view_choices= []
        vw_prefix = attrgetter('vw_prefix')
        item1 = itemgetter(1)
        for app_label, opts in BaseViewWork.vw.items():
            app = apps.get_app_config(app_label)
            urls = sys.modules[f'{app.module.__name__}.urls']
            namespace = getattr(urls, 'app_name', None) or app.module.__name__
            namespace = f'{namespace}:' if settings.USE_APP_NAMESPACE else ''
            views = filter(lambda v: not vw_prefix(v[1]) or not v[0].startswith(vw_prefix(v[1])), opts.items())
            views = list(map(item1, views))
            options = [(f'{namespace}{v.vw_name}', f'{v.vw_verbose_name}: {v.vw_name}') for v in views]
            options.sort(key=item1)
            view_choices.append((app.verbose_name, options))

        view_choices.sort(key=lambda opt: opt[0])
        view_choices.insert(0, BLANK_CHOICE_DASH[0])

        self.fields['view'].choices = view_choices
        self.fields['parent'].queryset = Menu.objects.filter(view='').order_by('name_i18n')
        self.fields['name_i18n'].required = True

    class Meta:
        model = Menu
        fields = '__all__'
        exclude = ('name',)
        widgets = {
            'parent': Select2()
        }

    @staticmethod
    def _strip(value):
        return (value or '').strip()

    def clean_name_i18n(self):
        return self._strip(self.cleaned_data.get('name_i18n'))

    def clean(self):
        cleaned_data = super().clean()
        for lang in {get_language(), dj_settings.LANGUAGE_CODE}:
            field_name = build_localized_fieldname('name', lang)
            cleaned_data[field_name] = self._strip(cleaned_data.get(field_name)) or cleaned_data.get('name_i18n', '')
        return cleaned_data
コード例 #10
0
ファイル: purchase.py プロジェクト: chiora93/repanier
class PurchaseForm(forms.ModelForm):
    product = forms.ChoiceField(
        label=_("Product"), widget=Select2(select2attrs={'width': '450px'}))
    delivery = forms.ChoiceField(label=_("Delivery point"),
                                 widget=SelectAdminDeliveryWidget())

    def clean_product(self):
        product_id = sint(self.cleaned_data.get("product"), 0)
        if product_id <= 0:
            if product_id == -1:
                self.add_error(
                    'product',
                    _("Please select first a producer in the filter of previous screen"
                      ))
            else:
                self.add_error(
                    'product',
                    _("No more product to add. Please update a product of previous screen"
                      ))
        return product_id

    def clean(self):
        if any(self.errors):
            # Don't bother validating the formset unless each form is valid on its own
            return
        if self.instance.id is None:
            quantity_ordered = self.cleaned_data.get("quantity_ordered",
                                                     DECIMAL_ZERO)
            quantity_invoiced = self.cleaned_data.get("quantity_invoiced",
                                                      DECIMAL_ZERO)
            if quantity_ordered == quantity_invoiced == DECIMAL_ZERO:
                self.add_error("quantity_ordered",
                               _('The quantity must be different than zero.'))
                self.add_error("quantity_invoiced",
                               _('The quantity must be different than zero.'))
        self._validate_unique = False

    class Meta:
        model = Purchase
        fields = "__all__"
        widgets = {
            'permanence': SelectAdminPermanenceWidget(),
            'customer': Select2(select2attrs={'width': '450px'})
        }
コード例 #11
0
ファイル: box.py プロジェクト: ryanbagwell/repanier
 class Meta:
     widgets = {
         'product': Select2(select2attrs={'width': '450px'})
     }
コード例 #12
0
 class Meta:
     widgets = {
         'customer': Select2(select2attrs={'width': '450px'})
     }
コード例 #13
0
 class Meta:
     widgets = {
         'offer_item': Select2(select2attrs={'width': '450px'})
     }
コード例 #14
0
 class Meta:
     widgets = {"offer_item": Select2(select2attrs={"width": "450px"})}