class PaymentMethodForm(forms.Form): paymentmethod = forms.ChoiceField(label=_('Payment method'), choices=labelled_payment_choices(), widget=forms.RadioSelect, required=True) def __init__(self, *args, **kwargs): try: cart = kwargs['cart'] del kwargs['cart'] except KeyError: cart = None try: order = kwargs['order'] del kwargs['order'] except KeyError: order = None super(forms.Form, self).__init__(*args, **kwargs) # Send a signal to perform additional filtering of available payment methods. # Receivers have cart/order passed in variables to check the contents and modify methods # list if neccessary. payment_choices = labelled_payment_choices() signals.payment_methods_query.send(PaymentMethodForm, methods=payment_choices, cart=cart, order=order) if len(payment_choices) == 1: self.fields['paymentmethod'].widget = forms.HiddenInput( attrs={'value': payment_choices[0][0]}) else: self.fields['paymentmethod'].widget = forms.RadioSelect( attrs={'value': payment_choices[0][0]}) self.fields['paymentmethod'].choices = payment_choices
def __init__(self, *args, **kwargs): try: cart = kwargs["cart"] del kwargs["cart"] except KeyError: cart = None try: order = kwargs["order"] del kwargs["order"] except KeyError: order = None super(forms.Form, self).__init__(*args, **kwargs) # Send a signal to perform additional filtering of available payment methods. # Receivers have cart/order passed in variables to check the contents and modify methods # list if neccessary. payment_choices = labelled_payment_choices() signals.payment_methods_query.send( PaymentMethodForm, methods=payment_choices, cart=cart, order=order ) if len(payment_choices) == 1: self.fields["paymentmethod"].widget = forms.HiddenInput( attrs={"value": payment_choices[0][0]} ) else: self.fields["paymentmethod"].widget = forms.RadioSelect( attrs={"value": payment_choices[0][0]} ) self.fields["paymentmethod"].choices = payment_choices self.fields["paymentmethod"].initial = payment_choices[0][0]
def __init__(self, *args, **kwargs): try: cart = kwargs["cart"] del kwargs["cart"] except KeyError: cart = None try: order = kwargs["order"] del kwargs["order"] except KeyError: order = None super(forms.Form, self).__init__(*args, **kwargs) # Send a signal to perform additional filtering of available payment methods. # Receivers have cart/order passed in variables to check the contents and modify methods # list if neccessary. payment_choices = labelled_payment_choices() signals.payment_methods_query.send(PaymentMethodForm, methods=payment_choices, cart=cart, order=order) if len(payment_choices) == 1: self.fields["paymentmethod"].widget = forms.HiddenInput( attrs={"value": payment_choices[0][0]}) else: self.fields["paymentmethod"].widget = forms.RadioSelect( attrs={"value": payment_choices[0][0]}) self.fields["paymentmethod"].choices = payment_choices self.fields["paymentmethod"].initial = payment_choices[0][0]
def __init__(self, choices="__DYNAMIC__", *args, **kwargs): if choices == "__DYNAMIC__": kwargs["choices"] = labelled_payment_choices() super(PaymentChoiceCharField, self).__init__(*args, **kwargs)