Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

forms.py 1.5KB

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