Ejemplo n.º 1
0
Archivo: forms.py Proyecto: 34/T
    def __init__(self, *args, **kwargs):
        contact = kwargs.pop('contact', None)
        self._contact = contact
        shop = kwargs.pop('shop', None)
        if not shop:
            shop = Config.objects.get_current()
        self._shop = shop
        
        super(AddressBookForm, self).__init__(*args, **kwargs)
        
        self.required_shipping_data = config_value('SHOP', 'REQUIRED_SHIPPING_DATA')
        self._local_only = shop.in_country_only
        self.enforce_state = config_value('SHOP','ENFORCE_STATE')
        
        self._default_country = shop.sales_country
        shipping_country = (self._contact and getattr(self._contact.shipping_address, 'country', None)) or self._default_country
        self.fields['country'] = forms.ModelChoiceField(shop.countries(), required=False, label=_(u'国家'), empty_label=None, initial=shipping_country.pk)
        
        if self.enforce_state:
            # Get areas for the initial country selected.
            shipping_areas = area_choices_for_country(shipping_country)

            shipping_state = (self._contact and getattr(self._contact.shipping_address, 'state', None)) or selection
            self.fields['province'] = forms.ChoiceField(choices=shipping_areas, initial=shipping_state, required=False, label=_(u'地区'))

        for f in self.fields:
            fld = self.fields[f]
            if fld.required:
                fld.label = (fld.label or f) + '*'
                
        log.info('Sending form_init signal: %s', self.__class__)
        form_init.send(self.__class__, form=self)
Ejemplo n.º 2
0
        def __init__(self, *args, **kwargs):
            super(PaymentContactInfoForm, self).__init__(*args, **kwargs)
            if not self.cart:
                request = threadlocals.get_current_request()
                self.cart = Cart.objects.from_request(request)

            self.fields['discount'] = forms.CharField(max_length=30, required=False)

            self.payment_required_fields = {}

            if config_value('PAYMENT', 'USE_DISCOUNTS'):
                if not self.fields['discount'].initial:
                    sale = _find_sale(self.cart)
                    if sale:
                        self.fields['discount'].initial = sale.code
            else:
                self.fields['discount'].widget = forms.HiddenInput()

            # Listeners of the form_init signal (below) may modify the dict of
            # payment_required_fields. For example, if your CUSTOM_PAYMENT requires
            # customer's city, put the following code in the listener:
            #
            #   form.payment_required_fields['CUSTOM_PAYMENT'] = ['city']
            #
            form_init.send(PaymentContactInfoForm, form=self)
Ejemplo n.º 3
0
    def __init__(self, *args, **kwargs):
        super(PaymentContactInfoForm, self).__init__(*args, **kwargs)
        if not self.cart:
            request = threadlocals.get_current_request()
            self.cart = Cart.objects.from_request(request)

        self.fields['discount'] = forms.CharField(max_length=30,
                                                  required=False)

        self.payment_required_fields = {}

        if config_value('PAYMENT', 'USE_DISCOUNTS'):
            if not self.fields['discount'].initial:
                sale = _find_sale(self.cart)
                if sale:
                    self.fields['discount'].initial = sale.code
        else:
            self.fields['discount'].widget = forms.HiddenInput()

        # Listeners of the form_init signal (below) may modify the dict of
        # payment_required_fields. For example, if your CUSTOM_PAYMENT requires
        # customer's city, put the following code in the listener:
        #
        #   form.payment_required_fields['CUSTOM_PAYMENT'] = ['city']
        #
        form_init.send(PaymentContactInfoForm, form=self)
Ejemplo n.º 4
0
    def __init__(self, *args, **kwargs):
        contact = kwargs.get('contact', None)
        initial = kwargs.get('initial', {})
        self.contact = contact
        form_initialdata.send(self.__class__,
                              form=self,
                              contact=contact,
                              initial=initial)

        kwargs['initial'] = initial
        super(RegistrationForm, self).__init__(*args, **kwargs)
        form_init.send(self.__class__, form=self, contact=contact)
Ejemplo n.º 5
0
    def __init__(self, *args, **kwargs):
        contact = kwargs.get('contact', None)
        initial = kwargs.get('initial', {})
        self.contact = contact
        form_initialdata.send(RegistrationForm,
            form=self,
            contact=contact,
            initial=initial)

        kwargs['initial'] = initial
        super(RegistrationForm, self).__init__(*args, **kwargs)
        form_init.send(RegistrationForm,
            form=self,
            contact=contact)
Ejemplo n.º 6
0
Archivo: forms.py Proyecto: 34/T
    def __init__(self, *args, **kwargs):
        initial = kwargs.get('initial', {})
        form_initialdata.send(self.__class__, form=self, initial=initial, contact = kwargs.get('contact', None))
        kwargs['initial'] = initial

        shop = kwargs.pop('shop', None)
        shippable = kwargs.pop('shippable', True)
        super(ContactInfoForm, self).__init__(*args, **kwargs)
        if not shop:
            shop = Config.objects.get_current()
        self._shop = shop
        self._shippable = shippable

        #self.required_billing_data = config_value('SHOP', 'REQUIRED_BILLING_DATA')
        self.required_shipping_data = config_value('SHOP', 'REQUIRED_SHIPPING_DATA')
        self._local_only = shop.in_country_only
        self.enforce_state = config_value('SHOP','ENFORCE_STATE')

        self._default_country = shop.sales_country
        shipping_country = (self._contact and getattr(self._contact.shipping_address, 'country', None)) or self._default_country
        #self.fields['country'] = forms.ModelChoiceField(shop.countries(), required=False, label=_(u'国家'), empty_label=None, initial=billing_country.pk)
        self.fields['country'] = forms.ModelChoiceField(shop.countries(), required=False, label=_(u'国家'), empty_label=None, initial=shipping_country.pk)

        if self.enforce_state:
            # if self.is_bound and not self._local_only:
            if self.is_bound and not self._local_only:
                # If the user has already chosen the country and submitted,
                # populate accordingly.
                #
                # We don't really care if country fields are empty;
                # area_choices_for_country() handles those cases properly.
                #billing_country_data = clean_field(self, 'country')
                shipping_country_data = clean_field(self, 'country')

                if shipping_country_data:
                    shipping_country = shipping_country_data

            # Get areas for the initial country selected.
            shipping_areas = area_choices_for_country(shipping_country)

            shipping_state = (self._contact and getattr(self._contact.shipping_address, 'state', None)) or selection
            self.fields['ship_state'] = forms.ChoiceField(choices=shipping_areas, initial=shipping_state, required=False, label=_(u'地区'))

        # slap a star on the required fields
        for f in self.fields:
            fld = self.fields[f]
            if fld.required:
                fld.label = (fld.label or f) + '*'
        log.info('Sending form_init signal: %s', self.__class__)
        form_init.send(self.__class__, form=self)
Ejemplo n.º 7
0
Archivo: forms.py Proyecto: 34/T
 def __init__(self, *args, **kwargs):
     super(PaymentShippingAddressBookForm, self).__init__(*args, **kwargs)
     
     if not self.cart:
         request = threadlocals.get_current_request()
         self.cart = Cart.objects.from_request(request)
     
     shipping_choices_ = shipping_choices()
     if len(shipping_choices_) == 1:
         self.fields['shippingmethod'].widget = forms.HiddenInput(attrs={'value' : shipping_choices_[0][0]})
     else:
         self.fields['shippingmethod'].widget = forms.RadioSelect(attrs={'value' : shipping_choices_[0][0]})
     self.fields['shippingmethod'].choices = shipping_choices_
     
     self.fields['discount'] = forms.CharField(max_length=30, required=False)
     if config_value('PAYMENT', 'USE_DISCOUNTS'):
         if not self.fields['discount'].initial:
             sale = _find_sale(self.cart)
             if sale:
                 self.fields['discount'].initial = sale.code
     else:
         self.fields['discount'].widget = forms.HiddenInput()
         
     form_init.send(PaymentContactInfoForm, form=self)
Ejemplo n.º 8
0
    def __init__(self, *args, **kwargs):
        initial = kwargs.get('initial', {})
        form_initialdata.send(ContactInfoForm,
                              form=self,
                              initial=initial,
                              contact=kwargs.get('contact', None))
        kwargs['initial'] = initial

        shop = kwargs.pop('shop', None)
        shippable = kwargs.pop('shippable', True)
        super(ContactInfoForm, self).__init__(*args, **kwargs)
        if not shop:
            shop = Config.objects.get_current()
        self._shop = shop
        self._shippable = shippable

        self.required_billing_data = config_value('SHOP',
                                                  'REQUIRED_BILLING_DATA')
        self.required_shipping_data = config_value('SHOP',
                                                   'REQUIRED_SHIPPING_DATA')
        self._local_only = shop.in_country_only
        self.enforce_state = config_value('SHOP', 'ENFORCE_STATE')

        self._default_country = shop.sales_country
        billing_country = (self._contact and getattr(
            self._contact.billing_address, 'country',
            None)) or self._default_country
        shipping_country = (self._contact and getattr(
            self._contact.shipping_address, 'country',
            None)) or self._default_country
        self.fields['country'] = forms.ModelChoiceField(
            shop.countries(),
            required=False,
            label=_('Country'),
            empty_label=None,
            initial=billing_country.pk)
        self.fields['ship_country'] = forms.ModelChoiceField(
            shop.countries(),
            required=False,
            label=_('Country'),
            empty_label=None,
            initial=shipping_country.pk)

        if self.enforce_state:
            # if self.is_bound and not self._local_only:
            if self.is_bound and not self._local_only:
                # If the user has already chosen the country and submitted,
                # populate accordingly.
                #
                # We don't really care if country fields are empty;
                # area_choices_for_country() handles those cases properly.
                billing_country_data = clean_field(self, 'country')
                shipping_country_data = clean_field(self, 'ship_country')

                # Has the user selected a country? If so, use it.
                if billing_country_data:
                    billing_country = billing_country_data

                if clean_field(self, "copy_address"):
                    shipping_country = billing_country
                elif shipping_country_data:
                    shipping_country = shipping_country_data

            # Get areas for the initial country selected.
            billing_areas = area_choices_for_country(billing_country)
            shipping_areas = area_choices_for_country(shipping_country)

            billing_state = (self._contact and getattr(
                self._contact.billing_address, 'state', None)) or selection
            self.fields['state'] = forms.ChoiceField(
                choices=billing_areas,
                initial=billing_state,
                label=_('State'),
                # if there are not states, then don't make it required. (first
                # choice is always either "--Please Select--", or "Not
                # Applicable")
                required=len(billing_areas) > 1)

            shipping_state = (self._contact and getattr(
                self._contact.shipping_address, 'state', None)) or selection
            self.fields['ship_state'] = forms.ChoiceField(
                choices=shipping_areas,
                initial=shipping_state,
                required=False,
                label=_('State'))

        for fname in self.required_billing_data:
            if fname == 'country' and self._local_only:
                continue

            # ignore the user if ENFORCE_STATE is on; if there aren't any
            # states, we might have made the billing state field not required in
            # the enforce_state block earlier, and we don't want the user to
            # make it required again.
            if fname == 'state' and self.enforce_state:
                continue

            self.fields[fname].required = True

        # if copy_address is on, turn of django's validation for required fields
        if not (self.is_bound and clean_field(self, "copy_address")):
            for fname in self.required_shipping_data:
                if fname == 'country' and self._local_only:
                    continue
                self.fields['ship_%s' % fname].required = True

        # slap a star on the required fields
        for f in self.fields:
            fld = self.fields[f]
            if fld.required:
                fld.label = (fld.label or f) + '*'
        log.info('Sending form_init signal: %s', ContactInfoForm)
        form_init.send(ContactInfoForm, form=self)
Ejemplo n.º 9
0
    def __init__(self, request, paymentmodule, *args, **kwargs):
        super(SimplePayShipForm, self).__init__(*args, **kwargs)

        try:
            order = Order.objects.from_request(request)
        except Order.DoesNotExist:
            order = None
        self.order = order
        self.orderpayment = None
        self.paymentmodule = paymentmodule

        try:
            self.tempCart = Cart.objects.from_request(request)
            if self.tempCart.numItems > 0:
                products = [item.product for item in self.tempCart.cartitem_set.all()]

        except Cart.DoesNotExist:
            self.tempCart = None

        try:
            self.tempContact = Contact.objects.from_request(request)
        except Contact.DoesNotExist:
            self.tempContact = None

        if kwargs.has_key('default_view_tax'):
            default_view_tax = kwargs['default_view_tax']
        else:
            default_view_tax = config_value_safe('TAX', 'TAX_SHIPPING', False)

        shipping_choices, shipping_dict = _get_shipping_choices(request, paymentmodule, self.tempCart, self.tempContact, default_view_tax=default_view_tax)


        cheapshipping = _get_cheapest_shipping(shipping_dict)
        self.cheapshipping = cheapshipping
        discount = None
        if order and order.discount_code:
            try:
                discount = Discount.objects.by_code(order.discount_code)
                if discount and discount.shipping == "FREECHEAP":
                    if cheapshipping:
                        shipping_choices = [opt for opt in shipping_choices if opt[0] == cheapshipping]
                        shipping_dict = {cheapshipping: shipping_dict[cheapshipping]}
            except Discount.DoesNotExist:
                pass
        
        # possibly hide the shipping based on store config
        shiphide = config_value('SHIPPING','HIDING')
        # Handle a partial payment and make sure we don't show a shipping choice after one has
        # already been chosen
        if self.order and self.order.is_partially_paid and shipping_dict.get(self.order.shipping_model, False):
            self.fields['shipping'] = forms.CharField(max_length=30, initial=self.order.shipping_model,
                widget=forms.HiddenInput(attrs={'value' : shipping_choices[0][0]}))
            self.shipping_hidden = True
        # Possibly hide if there is only 1 choise
        elif shiphide in ('YES', 'DESCRIPTION') and len(shipping_choices) == 1:
            self.fields['shipping'] = forms.CharField(max_length=30, initial=shipping_choices[0][0],
                widget=forms.HiddenInput(attrs={'value' : shipping_choices[0][0]}))
            if shiphide == 'DESCRIPTION':
                self.shipping_hidden = False
                self.shipping_description = shipping_choices[0][1]
            else:
                self.shipping_hidden = True
                self.shipping_description = ""
        elif len(shipping_choices) == 0:
            self.shipping_hidden = True
        else:
            self.fields['shipping'].choices = shipping_choices
            if config_value('SHIPPING','SELECT_CHEAPEST'):
                if cheapshipping is not None:
                    self.fields['shipping'].initial = cheapshipping
            self.shipping_hidden = False
                
        self.shipping_dict = shipping_dict
        form_init.send(SimplePayShipForm, form=self)
Ejemplo n.º 10
0
 def __init__(self, *args, **kwargs):
     initial = kwargs.get('initial', {})
     form_initialdata.send('CustomChargeForm', form=self, initial=initial)
     kwargs['initial'] = initial
     super(CustomChargeForm, self).__init__(*args, **kwargs)
     form_init.send(CustomChargeForm, form=self)
Ejemplo n.º 11
0
    def __init__(self, request, paymentmodule, *args, **kwargs):
        super(SimplePayShipForm, self).__init__(*args, **kwargs)

        try:
            order = Order.objects.from_request(request)
        except Order.DoesNotExist:
            order = None
        self.order = order
        self.orderpayment = None
        self.paymentmodule = paymentmodule

        try:
            self.tempCart = Cart.objects.from_request(request)
            if self.tempCart.numItems > 0:
                products = [
                    item.product for item in self.tempCart.cartitem_set.all()
                ]

        except Cart.DoesNotExist:
            self.tempCart = None

        try:
            self.tempContact = Contact.objects.from_request(request)
        except Contact.DoesNotExist:
            self.tempContact = None

        if kwargs.has_key('default_view_tax'):
            default_view_tax = kwargs['default_view_tax']
        else:
            default_view_tax = config_value_safe('TAX', 'TAX_SHIPPING', False)

        shipping_choices, shipping_dict = _get_shipping_choices(
            request,
            paymentmodule,
            self.tempCart,
            self.tempContact,
            default_view_tax=default_view_tax)

        cheapshipping = _get_cheapest_shipping(shipping_dict)
        self.cheapshipping = cheapshipping
        discount = None
        if order and order.discount_code:
            try:
                discount = Discount.objects.by_code(order.discount_code)
                # 'discount' object could be NullDiscount instance
                if discount and hasattr(
                        discount,
                        'shipping') and discount.shipping == "FREECHEAP":
                    if cheapshipping:
                        shipping_choices = [
                            opt for opt in shipping_choices
                            if opt[0] == cheapshipping
                        ]
                        shipping_dict = {
                            cheapshipping: shipping_dict[cheapshipping]
                        }
            except Discount.DoesNotExist:
                pass

        # possibly hide the shipping based on store config
        shiphide = config_value('SHIPPING', 'HIDING')
        # Handle a partial payment and make sure we don't show a shipping choice after one has
        # already been chosen
        if self.order and self.order.is_partially_paid and shipping_dict.get(
                self.order.shipping_model, False):
            self.fields['shipping'] = forms.CharField(
                max_length=30,
                initial=self.order.shipping_model,
                widget=forms.HiddenInput(
                    attrs={'value': shipping_choices[0][0]}))
            self.shipping_hidden = True
        # Possibly hide if there is only 1 choise
        elif shiphide in ('YES', 'DESCRIPTION') and len(shipping_choices) == 1:
            self.fields['shipping'] = forms.CharField(
                max_length=30,
                initial=shipping_choices[0][0],
                widget=forms.HiddenInput(
                    attrs={'value': shipping_choices[0][0]}))
            if shiphide == 'DESCRIPTION':
                self.shipping_hidden = False
                self.shipping_description = shipping_choices[0][1]
            else:
                self.shipping_hidden = True
                self.shipping_description = ""
        elif len(shipping_choices) == 0:
            self.shipping_hidden = True
        else:
            self.fields['shipping'].choices = shipping_choices
            if config_value('SHIPPING', 'SELECT_CHEAPEST'):
                if cheapshipping is not None:
                    self.fields['shipping'].initial = cheapshipping
            self.shipping_hidden = False

        self.shipping_dict = shipping_dict
        form_init.send(SimplePayShipForm, form=self)
Ejemplo n.º 12
0
 def __init__(self, *args, **kwargs):
     initial = kwargs.get('initial', {})
     form_initialdata.send('CustomChargeForm', form=self, initial=initial)
     kwargs['initial'] = initial
     super(CustomChargeForm, self).__init__(*args, **kwargs)
     form_init.send(CustomChargeForm, form=self)
Ejemplo n.º 13
0
    def __init__(self, *args, **kwargs):
        initial = kwargs.get('initial', {})
        form_initialdata.send(ContactInfoForm, form=self, initial=initial, contact=kwargs.get('contact', None))
        kwargs['initial'] = initial

        shop = kwargs.pop('shop', None)
        shippable = kwargs.pop('shippable', True)
        super(ContactInfoForm, self).__init__(*args, **kwargs)
        if not shop:
            shop = Config.objects.get_current()
        self._shop = shop
        self._shippable = shippable

        self.required_billing_data = config_value('SHOP', 'REQUIRED_BILLING_DATA')
        self.required_shipping_data = config_value('SHOP', 'REQUIRED_SHIPPING_DATA')
        self._local_only = shop.in_country_only
        self.enforce_state = config_value('SHOP', 'ENFORCE_STATE')

        self._default_country = shop.sales_country
        billing_country = (self._contact and getattr(self._contact.billing_address, 'country', None)) or self._default_country
        shipping_country = (self._contact and getattr(self._contact.shipping_address, 'country', None)) or self._default_country
        self.fields['country'] = forms.ModelChoiceField(shop.countries(), required=False, label=_('Country'), empty_label=None, initial=billing_country.pk)
        self.fields['ship_country'] = forms.ModelChoiceField(shop.countries(), required=False, label=_('Country'), empty_label=None, initial=shipping_country.pk)

        if self.enforce_state:
            # if self.is_bound and not self._local_only:
            if self.is_bound and not self._local_only:
                # If the user has already chosen the country and submitted,
                # populate accordingly.
                #
                # We don't really care if country fields are empty;
                # area_choices_for_country() handles those cases properly.
                billing_country_data = clean_field(self, 'country')
                shipping_country_data = clean_field(self, 'ship_country')

                # Has the user selected a country? If so, use it.
                if billing_country_data:
                    billing_country = billing_country_data

                if clean_field(self, "copy_address"):
                    shipping_country = billing_country
                elif shipping_country_data:
                    shipping_country = shipping_country_data

            # Get areas for the initial country selected.
            billing_areas = area_choices_for_country(billing_country)
            shipping_areas = area_choices_for_country(shipping_country)

            billing_state = (self._contact and getattr(self._contact.billing_address, 'state', None)) or selection
            self.fields['state'] = forms.ChoiceField(choices=billing_areas,
                                                     initial=billing_state,
                                                     label=_('State'),
                # if there are not states, then don't make it required. (first
                # choice is always either "--Please Select--", or "Not
                # Applicable")
                required=len(billing_areas) > 1)

            shipping_state = (self._contact and getattr(self._contact.shipping_address, 'state', None)) or selection
            self.fields['ship_state'] = forms.ChoiceField(choices=shipping_areas, initial=shipping_state, required=False, label=_('State'))

        for fname in self.required_billing_data:
            if fname == 'country' and self._local_only:
                continue

            # ignore the user if ENFORCE_STATE is on; if there aren't any
            # states, we might have made the billing state field not required in
            # the enforce_state block earlier, and we don't want the user to
            # make it required again.
            if fname == 'state' and self.enforce_state:
                continue

            self.fields[fname].required = True

        # if copy_address is on, turn of django's validation for required fields
        if not (self.is_bound and clean_field(self, "copy_address")):
            for fname in self.required_shipping_data:
                if fname == 'country' and self._local_only:
                    continue
                self.fields['ship_%s' % fname].required = True

        # slap a star on the required fields
        for f in self.fields:
            fld = self.fields[f]
            if fld.required:
                fld.label = (fld.label or f) + '*'
        log.info('Sending form_init signal: %s', ContactInfoForm)
        form_init.send(ContactInfoForm, form=self)