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)
def get(self, *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. self.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() self.initial=init_data form_initialdata.send( sender=MyCheckoutForm, 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
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)
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)
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)
def get(self, request, *args, **kwargs): contact = self.get_contact() init_data = self.get_initial() 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)
def get(self, request, *args, **kwargs): contact = self.get_contact() init_data = self.get_initial() 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)
def contact_form(context): request = context['request'] cart = context['cart'] shop = context['shop'] init_data = {} try: contact = Contact.objects.from_request(request, create=False) except Contact.DoesNotExist: contact = None if contact: 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: request.session.set_test_cookie() if request.user.is_authenticated(): if request.user.email: init_data['email'] = request.user.email if request.user.first_name: init_data['first_name'] = request.user.get_full_name() form_initialdata.send(sender=PaymentContactInfoForm, initial=init_data, contact=contact, cart=cart, shop=shop) form = PaymentContactInfoForm( cart=cart, shop=shop, contact=contact, initial=init_data) return { 'form': form, }
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)
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)
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)
def contact_info(request, **kwargs): """View which collects demographic information from customer.""" #First verify that the cart exists and has items tempCart = Cart.objects.from_request(request) if tempCart.numItems == 0: return render_to_response('shop/checkout/empty_cart.html', context_instance=RequestContext(request)) if not 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) init_data = {} shop = Config.objects.get_current() if request.user.is_authenticated(): if request.user.email: init_data['email'] = request.user.email # -arthur- #if request.user.first_name: # init_data['first_name'] = request.user.first_name #if request.user.last_name: # init_data['last_name'] = request.user.last_name try: contact = Contact.objects.from_request(request, create=False) except Contact.DoesNotExist: contact = None try: order = Order.objects.from_request(request) if order.discount_code: init_data['discount'] = order.discount_code except Order.DoesNotExist: pass if request.method == "POST": new_data = request.POST.copy() if not tempCart.is_shippable: new_data['copy_address'] = True form = PaymentContactInfoForm(data=new_data, shop=shop, contact=contact, shippable=tempCart.is_shippable, initial=init_data, cart=tempCart) if form.is_valid(): if contact is None and request.user and request.user.is_authenticated(): contact = Contact(user=request.user) custID = form.save(request, cart=tempCart, contact=contact) request.session[CUSTOMER_ID] = custID modulename = new_data['paymentmethod'] if not modulename.startswith('PAYMENT_'): modulename = 'PAYMENT_' + modulename paymentmodule = config_get_group(modulename) url = lookup_url(paymentmodule, 'satchmo_checkout-step2') return http.HttpResponseRedirect(url) else: log.debug("Form errors: %s", form.errors) else: 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) # -arthur- #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 else: # Allow them to login from this page. request.session.set_test_cookie() #Request additional init_data form_initialdata.send(sender=PaymentContactInfoForm, initial=init_data, contact=contact, cart=tempCart, shop=shop) form = PaymentContactInfoForm( shop=shop, contact=contact, shippable=tempCart.is_shippable, initial=init_data, cart=tempCart) if shop.in_country_only: only_country = shop.sales_country else: only_country = None context = RequestContext(request, { 'form': form, 'country': only_country, 'paymentmethod_ct': len(form.fields['paymentmethod'].choices) }) return render_to_response('shop/checkout/form.html', context_instance=context)
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)
def contact_info(request, **kwargs): """View which collects demographic information from customer.""" #First verify that the cart exists and has items tempCart = Cart.objects.from_request(request) if tempCart.numItems == 0: return render_to_response('shop/checkout/empty_cart.html', context_instance=RequestContext(request)) if not 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) init_data = {} shop = Config.objects.get_current() if request.user.is_authenticated(): if request.user.email: init_data['email'] = request.user.email if request.user.first_name: init_data['first_name'] = request.user.first_name if request.user.last_name: init_data['last_name'] = request.user.last_name try: contact = Contact.objects.from_request(request, create=False) except Contact.DoesNotExist: contact = None try: order = Order.objects.from_request(request) if order.discount_code: init_data['discount'] = order.discount_code except Order.DoesNotExist: pass if request.method == "POST": new_data = request.POST.copy() if not tempCart.is_shippable: new_data['copy_address'] = True form = PaymentContactInfoForm(data=new_data, shop=shop, contact=contact, shippable=tempCart.is_shippable, initial=init_data, cart=tempCart) if form.is_valid(): if contact is None and request.user and request.user.is_authenticated( ): contact = Contact(user=request.user) custID = form.save(request, cart=tempCart, contact=contact) request.session[CUSTOMER_ID] = custID modulename = new_data['paymentmethod'] if not modulename.startswith('PAYMENT_'): modulename = 'PAYMENT_' + modulename paymentmodule = config_get_group(modulename) url = lookup_url(paymentmodule, 'satchmo_checkout-step2') return http.HttpResponseRedirect(url) else: log.debug("Form errors: %s", form.errors) else: 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() #Request additional init_data form_initialdata.send(sender=PaymentContactInfoForm, initial=init_data, contact=contact, cart=tempCart, shop=shop) form = PaymentContactInfoForm(shop=shop, contact=contact, shippable=tempCart.is_shippable, initial=init_data, cart=tempCart) if shop.in_country_only: only_country = shop.sales_country else: only_country = None context = RequestContext( request, { 'form': form, 'country': only_country, 'paymentmethod_ct': len(form.fields['paymentmethod'].choices) }) return render_to_response('shop/checkout/form.html', context_instance=context)
def confirm_order_info(request, template=None): '''确认订单信息''' #First verify that the cart exists and has items tempCart = Cart.objects.from_request(request) if tempCart.numItems == 0: return render_to_response('shop/checkout/empty_cart.html', context_instance=RequestContext(request)) if not 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) init_data = {} shop = Config.objects.get_current() try: contact = Contact.objects.from_request(request, create=True) init_data['contact'] = contact.id except Contact.DoesNotExist: contact = None order = None try: order = Order.objects.from_request(request) if order.discount_code: init_data['discount'] = order.discount_code except Order.DoesNotExist: pass if request.method == "POST": pass else: if contact: if contact.shipping_address: for item in contact.shipping_address.__dict__.keys(): init_data[item] = getattr(contact.shipping_address,item) else: # Allow them to login from this page. request.session.set_test_cookie() #Request additional init_data form_initialdata.send(sender=PaymentShippingAddressBookForm, initial=init_data, contact=contact, cart=tempCart, shop=shop) form = PaymentShippingAddressBookForm( shop=shop, contact=contact, initial=init_data) if shop.in_country_only: only_country = shop.sales_country else: only_country = None context = RequestContext(request, { 'form': form, 'country': only_country, 'contact': contact, 'addressbooklist': contact.addressbook_set.all(), 'order': order, #'paymentmethod_ct': len(form.fields['paymentmethod'].choices) }) return render_to_response('shop/checkout/form.html', context_instance=context)