PaymentModules not updated after settings change

Issue #335 resolved
Anonymous created an issue

After rolling out a web shop I've discovered that the PaymentModules aren't updated in the form in checkout step 1. This is the old code for the forms:

{{{

class PaymentMethodForm(forms.Form): _choices = payment_choices() if len(_choices) > 0: if len(_choices) > 1: _paymentwidget = forms.RadioSelect else: _paymentwidget = forms.HiddenInput(attrs={'value':_choices[0][0]})

    paymentmethod = forms.ChoiceField(label=_('Payment method'),
                      choices=_choices,
                      widget=_paymentwidget,
                      required=True)

class PaymentContactInfoForm(ContactInfoForm): _choices = payment_choices() if len(_choices) > 0: if len(_choices) > 1: _paymentwidget = forms.RadioSelect else: _paymentwidget = forms.HiddenInput(attrs={'value' : _choices[0][0]})

    paymentmethod = forms.ChoiceField(label=_('Payment method'),
                      choices=_choices,
                      widget=_paymentwidget,
                      required=True)

}}}

And this is the new code:

{{{ class PaymentMethodForm(forms.Form):

paymentmethod = forms.ChoiceField(label=_('Payment method'),
                                  choices=[],
                                  required=True)

def __init__(self, *args, **kwargs):
    super(PaymentMethodForm, self).__init__(*args, **kwargs)
    _choices = payment_choices()
    if len(_choices) > 0:
        if len(_choices) > 1:
            _paymentwidget = forms.RadioSelect(choices=_choices)
        else:
            _paymentwidget = forms.HiddenInput(attrs={'value' : _choices[0][0]})

        self.paymentmethod.choices = _choices
        self.paymentmethod.widget = _paymentwidget

class PaymentContactInfoForm(ContactInfoForm):

paymentmethod = forms.ChoiceField(label=_('Payment method'),
                                  choices=[],
                                  required=True)

def __init__(self, *args, **kwargs):
    super(PaymentContactInfoForm, self).__init__(*args, **kwargs)
    _choices = payment_choices()
    if len(_choices) > 0:
        if len(_choices) > 1:
            _paymentwidget = forms.RadioSelect(choices=_choices)
        else:
            _paymentwidget = forms.HiddenInput(attrs={'value' : _choices[0][0]})
        self.fields['paymentmethod'].choices = _choices
        self.fields['paymentmethod'].widget = _paymentwidget

}}}

Reported by jhhazelaar

Comments (3)

  1. Anonymous

    That's pretty good, partially eliminating the need for a restart. However, I think a restart will still be needed to pick up the urlpatterns for the new methods.

    That said, this is a good first step, I'll review and see if I can commit your work.

  2. Log in to comment