Ejemplo n.º 1
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.º 2
0
    def get(self, request, *args, **kwargs):
        contact = self.get_contact()
        init_data = self.get_initial()

        if not self.request.user.is_authenticated() and \
                config_value('SHOP', 'AUTHENTICATION_REQUIRED'):
            url = urlresolvers.reverse('satchmo_checkout_auth_required')
            thisurl = urlresolvers.reverse('satchmo_checkout-step1')
            return http.HttpResponseRedirect(url + "?next=" + thisurl)

        if contact:
            # If a person has their contact info,
            # make sure we populate it in the form
            for item in contact.__dict__.keys():
                init_data[item] = getattr(contact, item)
            if contact.shipping_address:
                for item in contact.shipping_address.__dict__.keys():
                    init_data["ship_"+item] = getattr(
                        contact.shipping_address,
                        item
                    )
            if contact.billing_address:
                for item in contact.billing_address.__dict__.keys():
                    init_data[item] = getattr(contact.billing_address, item)
            if contact.primary_phone:
                init_data['phone'] = contact.primary_phone.phone
        else:
            # Allow them to login from this page.
            request.session.set_test_cookie()

        tempCart = self.get_cart()
        if (not tempCart) or (tempCart.numItems == 0):
            return render_to_response('shop/checkout/empty_cart.html',
                            context_instance=RequestContext(self.request))

        shop = self.get_shop()

        form_initialdata.send(
            sender=self.get_form_class(),
            initial=init_data,
            contact=contact,
            cart=tempCart,
            shop=shop
        )
        self._initial_data = init_data

        self._form_extrakwargs['shop'] = shop
        self._form_extrakwargs['contact'] = contact
        self._form_extrakwargs['shippable'] = tempCart.is_shippable
        self._form_extrakwargs['cart'] = tempCart

        return super(CheckoutForm, self).get(request, *args, **kwargs)
Ejemplo n.º 3
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.º 4
0
    def get(self, request, *args, **kwargs):
        contact = self.get_contact()
        init_data = self.get_initial()

        if not self.request.user.is_authenticated() and \
                config_value('SHOP', 'AUTHENTICATION_REQUIRED'):
            url = urlresolvers.reverse('satchmo_checkout_auth_required')
            thisurl = urlresolvers.reverse('satchmo_checkout-step1')
            return http.HttpResponseRedirect(url + "?next=" + thisurl)

        if contact:
            # If a person has their contact info,
            # make sure we populate it in the form
            for item in contact.__dict__.keys():
                init_data[item] = getattr(contact, item)
            if contact.shipping_address:
                for item in contact.shipping_address.__dict__.keys():
                    init_data["ship_" + item] = getattr(
                        contact.shipping_address, item)
            if contact.billing_address:
                for item in contact.billing_address.__dict__.keys():
                    init_data[item] = getattr(contact.billing_address, item)
            if contact.primary_phone:
                init_data['phone'] = contact.primary_phone.phone
        else:
            # Allow them to login from this page.
            request.session.set_test_cookie()

        tempCart = self.get_cart()
        if (not tempCart) or (tempCart.numItems == 0):
            return render_to_response('shop/checkout/empty_cart.html',
                                      context_instance=RequestContext(
                                          self.request))

        shop = self.get_shop()

        form_initialdata.send(sender=self.get_form_class(),
                              initial=init_data,
                              contact=contact,
                              cart=tempCart,
                              shop=shop)
        self._initial_data = init_data

        self._form_extrakwargs['shop'] = shop
        self._form_extrakwargs['contact'] = contact
        self._form_extrakwargs['shippable'] = tempCart.is_shippable
        self._form_extrakwargs['cart'] = tempCart

        return super(CheckoutForm, self).get(request, *args, **kwargs)
Ejemplo n.º 5
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')

        organization_name = self._contact and getattr(
            self._contact.organization, 'name', '')
        self.fields['organization'] = forms.CharField(
            max_length=50,
            label=_('Organization'),
            required=False,
            initial=organization_name)
        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 self._shippable and 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.º 6
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')

        organization_name = self._contact and getattr(self._contact.organization, 'name', '')
        self.fields['organization'] = forms.CharField(max_length=50, label=_('Organization'), required=False, initial=organization_name)
        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.º 7
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.º 8
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)