You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

forms.py 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. from django import forms
  2. from django.db.models import get_model
  3. from django.contrib.auth.forms import AuthenticationForm
  4. class ShippingAddressForm(forms.ModelForm):
  5. def __init__(self, *args, **kwargs):
  6. super(ShippingAddressForm,self ).__init__(*args, **kwargs)
  7. self.set_country_queryset()
  8. def set_country_queryset(self):
  9. self.fields['country'].queryset = get_model('address', 'country')._default_manager.filter(is_shipping_country=True)
  10. class Meta:
  11. model = get_model('order', 'shippingaddress')
  12. exclude = ('user', 'search_text')
  13. class GatewayForm(AuthenticationForm):
  14. username = forms.EmailField(label="My email address is")
  15. NEW, EXISTING = 'new', 'existing'
  16. CHOICES = ((NEW, 'No, I am a new customer'),
  17. (EXISTING, 'Yes, I have a password'))
  18. options = forms.ChoiceField(widget=forms.widgets.RadioSelect,
  19. choices=CHOICES)
  20. def clean(self):
  21. cleaned_data = self.cleaned_data
  22. if self.is_guest_checkout():
  23. if 'password' in self.errors:
  24. del self.errors['password']
  25. return cleaned_data
  26. return super(GatewayForm, self).clean()
  27. def is_guest_checkout(self):
  28. return self.cleaned_data.get('options', None) == self.NEW
  29. # The BillingAddress form is in oscar.apps.payment.forms