Exemple #1
0
    def __init__(self,
                 querysets,
                 empty_label=_("Send to everyone"),
                 required=True,
                 widget=None,
                 label=None,
                 initial=None,
                 help_text="",
                 limit_choices_to=None,
                 **kwargs):
        if required and (initial is not None):
            self.empty_label = None
        else:
            self.empty_label = empty_label

        # Call Field instead of ChoiceField __init__() because we don't need
        # ChoiceField.__init__().
        Field.__init__(self,
                       required=required,
                       widget=widget,
                       label=label,
                       initial=initial,
                       help_text=help_text,
                       **kwargs)

        self._querysets = querysets
Exemple #2
0
    def __init__(
        self,
        *,
        payment_modes=None,
        empty_label=_("Choisissez votre moyen de paiement"),
        required=True,
        initial=None,
        label=_("Mode de paiement"),
        **kwargs
    ):

        if payment_modes == "ALL":
            self._payment_modes = settings.PAYMENT_MODES
        elif payment_modes is None:
            self._payment_modes = [PAYMENT_MODES["system_pay"], PAYMENT_MODES["check"]]
        else:
            self._payment_modes = payment_modes

        if required:
            self.empty_label = None
        else:
            self.empty_label = empty_label

        # bypassing ChoiceField constructor, see ModelChoiceField implementation for reference
        Field.__init__(self, required=required, label=label, initial=initial, **kwargs)
        self.widget.choices = self.choices
Exemple #3
0
    def __init__(
            self,
            *,
            payment_modes,
            empty_label=_("Choisissez votre moyen de paiement"),
            required=True,
            initial=None,
            label=_("Mode de paiement"),
            **kwargs,
    ):

        self._payment_modes = [
            PAYMENT_MODES[p] if isinstance(p, str) else p
            for p in payment_modes
        ]

        if required:
            self.empty_label = None
        else:
            self.empty_label = empty_label

        # bypassing ChoiceField constructor, see ModelChoiceField implementation for reference
        Field.__init__(self,
                       required=required,
                       label=label,
                       initial=initial,
                       **kwargs)
        self.widget.choices = self.choices