<s> from django import forms <EOL> from django . contrib . auth . forms import AuthenticationForm <EOL> from django . utils . translation import ugettext_lazy as _ <EOL> from oscar . apps . address . forms import AbstractAddressForm <EOL> from oscar . apps . customer . utils import normalise_email <EOL> from oscar . core . compat import get_user_model <EOL> from oscar . core . loading import get_model <EOL> from oscar . views . generic import PhoneNumberMixin <EOL> User = get_user_model ( ) <EOL> Country = get_model ( '<STR_LIT:address>' , '<STR_LIT>' ) <EOL> class ShippingAddressForm ( PhoneNumberMixin , AbstractAddressForm ) : <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> super ( ShippingAddressForm , self ) . __init__ ( * args , ** kwargs ) <EOL> self . adjust_country_field ( ) <EOL> def adjust_country_field ( self ) : <EOL> countries = Country . _default_manager . filter ( <EOL> is_shipping_country = True ) <EOL> if len ( countries ) == <NUM_LIT:1> : <EOL> self . fields . pop ( '<STR_LIT>' , None ) <EOL> self . instance . country = countries [ <NUM_LIT:0> ] <EOL> else : <EOL> self . fields [ '<STR_LIT>' ] . queryset = countries <EOL> self . fields [ '<STR_LIT>' ] . empty_label = None <EOL> class Meta : <EOL> model = get_model ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> fields = [ <EOL> '<STR_LIT:title>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT:state>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> ] <EOL> class ShippingMethodForm ( forms . Form ) : <EOL> method_code = forms . ChoiceField ( widget = forms . HiddenInput ) <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> methods = kwargs . pop ( '<STR_LIT>' , [ ] ) <EOL> super ( ShippingMethodForm , self ) . __init__ ( * args , ** kwargs ) <EOL> self . fields [ '<STR_LIT>' ] . choices = ( ( m . code , m . name ) for m in methods ) <EOL> class GatewayForm ( AuthenticationForm ) : <EOL> username = forms . EmailField ( label = _ ( "<STR_LIT>" ) ) <EOL> GUEST , NEW , EXISTING = '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' <EOL> CHOICES = ( <EOL> ( GUEST , _ ( '<STR_LIT>' ) ) , <EOL> ( NEW , _ ( '<STR_LIT>' <EOL> '<STR_LIT>' ) ) , <EOL> ( EXISTING , _ ( '<STR_LIT>' ) ) ) <EOL> options = forms . ChoiceField ( widget = forms . widgets . RadioSelect , <EOL> choices = CHOICES , initial = GUEST ) <EOL> def clean_username ( self ) : <EOL> return normalise_email ( self . cleaned_data [ '<STR_LIT:username>' ] ) <EOL> def clean ( self ) : <EOL> if self . is_guest_checkout ( ) or self . is_new_account_checkout ( ) : <EOL> if '<STR_LIT:password>' in self . errors : <EOL> del self . errors [ '<STR_LIT:password>' ] <EOL> if '<STR_LIT:username>' in self . cleaned_data : <EOL> email = normalise_email ( self . cleaned_data [ '<STR_LIT:username>' ] ) <EOL> if User . _default_manager . filter ( email__iexact = email ) . exists ( ) : <EOL> msg = _ ( "<STR_LIT>" ) <EOL> self . _errors [ "<STR_LIT:username>" ] = self . error_class ( [ msg ] ) <EOL> return self . cleaned_data <EOL> return super ( GatewayForm , self ) . clean ( ) <EOL> def is_guest_checkout ( self ) : <EOL> return self . cleaned_data . get ( '<STR_LIT>' , None ) == self . GUEST <EOL> def is_new_account_checkout ( self ) : <EOL> return self . cleaned_data . get ( '<STR_LIT>' , None ) == self . NEW </s>
