• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python library.form_factory函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中postal.library.form_factory函数的典型用法代码示例。如果您正苦于以下问题:Python form_factory函数的具体用法?Python form_factory怎么用?Python form_factory使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了form_factory函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: address_inline

def address_inline(request, prefix, form):
    """displays the invoice address with localized fields
    """
    template_name = "lfs/customer/" + prefix + "_address_inline.html"
    country_code = get_country_code(request, prefix)
    if country_code != '':
        shop = lfs.core.utils.get_default_shop(request)
        countries = None
        if prefix == INVOICE_PREFIX:
            countries = shop.invoice_countries.all()
        else:
            countries = shop.shipping_countries.all()
        customer = customer_utils.get_or_create_customer(request)
        address_form_class = form_factory(country_code)
        if request.method == 'POST':
            if POSTAL_ADDRESS_L10N == True:
                address_form = address_form_class(prefix=prefix, data=request.POST,)
            else:
                address_form = PostalAddressForm(prefix=prefix, data=request.POST,)
            if countries is not None:
                address_form.fields["country"].choices = [(c.code.upper(), c.name) for c in countries]
        else:
            # If there are addresses intialize the form.
            initial = {}
            customer_selected_address = None
            if hasattr(customer, 'selected_' + prefix + '_address'):
                customer_selected_address = getattr(customer, 'selected_' + prefix + '_address')
            if customer_selected_address is not None:
                initial.update({
                    "line1": customer_selected_address.line1,
                    "line2": customer_selected_address.line2,
                    "city" : customer_selected_address.city,
                    "state": customer_selected_address.state,
                    "code": customer_selected_address.zip_code,
                    "country": customer_selected_address.country.code.upper(),
                })
                address_form = address_form_class(prefix=prefix, initial=initial)
            else:
                address_form = address_form_class(prefix=prefix)
                address_form.fields["country"].initial = country_code
            if countries is not None:
                address_form.fields["country"].choices = [(c.code.upper(), c.name) for c in countries]

    # Removes fields from address form if requested via settings.
    for i in range(1, 6):
        address_settings = getattr(settings, "POSTAL_ADDRESS_LINE%s" % i, None)
        try:
            if address_settings and address_settings[2] == False:
                del address_form.fields["line%s" % i]
        except IndexError:
            pass

    # if request via ajax don't display validity errors
    if request.is_ajax():
        address_form._errors = {}
    return render_to_string(template_name, RequestContext(request, {
        "address_form": address_form,
        "form": form,
        "settings": settings,
    }))
开发者ID:DenisVasiliev,项目名称:django-lfs,代码行数:60,代码来源:views.py


示例2: test_get_mx_address

    def test_get_mx_address(self):
        """
        Tests that we get the correct widget for Mexico
        """
        mx_form_class = form_factory("mx")
        self.assertNotEqual(mx_form_class, None)

        # only use required fields
        test_data = {
            'line1': 'Avenida Reforma',
            'line2': '1110',
            'line3': 'Centro',
            'city': 'Puebla',
            'state': 'Puebla',
            'code': '12345'
        }
        form = mx_form_class(data=test_data)

        self.assertEqual(form.fields['line1'].label.lower(), 'street')
        self.assertEqual(form.fields['line2'].label.lower(), 'number')
        self.assertEqual(form.fields['city'].label.lower(), 'city')
        self.assertEqual(form.fields['state'].label.lower(), 'state')
        self.assertEqual(form.fields['code'].label.lower(), 'zip code')

        from localflavor.mx.forms import MXStateSelect, MXZipCodeField
        self.assertIsInstance(form.fields['state'].widget, MXStateSelect)
        self.assertIsInstance(form.fields['code'], MXZipCodeField)
开发者ID:NB-Dev,项目名称:django-postal,代码行数:27,代码来源:test_l10n.py


示例3: address_inline

def address_inline(request, prefix="", country_code=None, template_name="postal/form.html"):
    """ Displays postal address with localized fields """

    country_prefix = "country"
    prefix = request.POST.get('prefix', prefix)

    if prefix:
        country_prefix = prefix + '-country'

    country_code = request.POST.get(country_prefix, country_code)
    form_class = form_factory(country_code=country_code)

    if request.method == "POST":
        data = {}
        for (key, val) in request.POST.items():
            if val is not None and len(val) > 0:
                data[key] = val
        data.update({country_prefix: country_code})

        form = form_class(prefix=prefix, initial=data)
    else:
        form = form_class(prefix=prefix)

    return render_to_string(template_name, RequestContext(request, {
        "form": form,
        "prefix": prefix,
    }))
开发者ID:sjhewitt,项目名称:django-postal,代码行数:27,代码来源:views.py


示例4: test_checkout_with_4_line_shipping_address

    def test_checkout_with_4_line_shipping_address(self):
        # login as our customer
        logged_in = self.client.login(username=self.username, password=self.password)
        self.assertEqual(logged_in, True)

        # test that our Netherlands form has only 4 address line fields
        nl_form_class = form_factory("NL")
        nl_form = nl_form_class()
        self.assertEqual('state' in nl_form.fields, False)
        self.assertEqual('code' in nl_form.fields, True)

        # check initial database quantities
        self.assertEquals(Address.objects.count(), 2)
        self.assertEquals(Customer.objects.count(), 1)
        self.assertEquals(Order.objects.count(), 0)

        # check we have no invoice or shipping phone or email prior to checkout
        our_customer = Customer.objects.all()[0]
        self.assertEqual(our_customer.selected_invoice_address.phone, None)
        self.assertEqual(our_customer.selected_invoice_address.email, None)
        self.assertEqual(our_customer.selected_shipping_address.phone, None)
        self.assertEqual(our_customer.selected_shipping_address.email, None)

        checkout_data = {'invoice-firstname': 'bob',
                         'invoice-lastname': 'builder',
                         'invoice-line1': 'de company',
                         'invoice-line2': 'de street',
                         'invoice-city': 'de area',
                         'invoice-state': 'de town',
                         'invoice-code': '1234AB',
                         'invoice-country': "NL",
                         'invoice-email': '[email protected]',
                         'invoice-phone': '1234567',
                         'shipping-firstname': 'hans',
                         'shipping-lastname': 'schmidt',
                         'shipping-line1': 'orianenberger strasse',
                         'shipping-line2': 'de town',
                         'shipping-city': 'stuff',
                         'shipping-state': 'BE',
                         'shipping-code': '1234AB',
                         'shipping-country': "NL",
                         'shipping-email': '[email protected]',
                         'shipping-phone': '7654321',
                         'payment_method': self.by_invoice.id,
                         }

        checkout_post_response = self.client.post(reverse('lfs_checkout'), checkout_data)
        self.assertRedirects(checkout_post_response, reverse('lfs_thank_you'), status_code=302, target_status_code=200,)

        # check database quantities post-checkout
        self.assertEquals(Address.objects.count(), 4)
        self.assertEquals(Customer.objects.count(), 1)
        self.assertEquals(Order.objects.count(), 1)

        # check our customer details post checkout
        our_customer = Customer.objects.all()[0]
        self.assertEqual(our_customer.selected_invoice_address.phone, "1234567")
        self.assertEqual(our_customer.selected_invoice_address.email, "[email protected]")
        self.assertEqual(our_customer.selected_shipping_address.phone, '7654321')
        self.assertEqual(our_customer.selected_shipping_address.email, "[email protected]")
开发者ID:ethirajit,项目名称:onlinepos,代码行数:60,代码来源:test_checkout.py


示例5: is_valid

    def is_valid(self):
        """
        Returns True if the postal and the additional form is valid.
        """
        if self.type == "shipping" and self.data.get("no_shipping"):
            return True

        if self.data:
            form_model = form_factory("%s-country" % self.type)
        else:
            form_model = form_factory(self.address.country.code.upper())
        postal_form = form_model(data=self.data, initial=self.get_address_as_dict(), prefix=self.type)

        address_form_model = self.get_form_model()
        address_form = address_form_model(data=self.data, instance=self.address, prefix=self.type)

        return postal_form.is_valid() and address_form.is_valid()
开发者ID:RS71,项目名称:django-lfs,代码行数:17,代码来源:utils.py


示例6: is_valid

    def is_valid(self):
        """
        Returns True if the postal and the additional form is valid.
        """
        if self.type == CHECKOUT_NOT_REQUIRED_ADDRESS and self.data.get("no_%s" % CHECKOUT_NOT_REQUIRED_ADDRESS):
            return True

        if self.data:
            form_model = form_factory(self.data.get("%s-country" % self.type, self.address.country.code.upper()))
        else:
            form_model = form_factory(self.address.country.code.upper())
        postal_form = form_model(data=self.data, initial=self.get_address_as_dict(), prefix=self.type)

        address_form_model = self.get_form_model()
        address_form = address_form_model(data=self.data, instance=self.address, prefix=self.type)

        return postal_form.is_valid() and address_form.is_valid()
开发者ID:DanielChu,项目名称:django-lfs,代码行数:17,代码来源:utils.py


示例7: test_4_line_address

 def test_4_line_address(self):
     netherlands_form_class = form_factory("nl")
     self.assertNotEqual(netherlands_form_class, None)
     test_data = {'code': '1234AB'}
     form = netherlands_form_class(data=test_data)
     self.assertEqual(form.fields['line1'].label.lower(), "street")
     self.assertEqual(form.fields['line2'].label.lower(), "area")
     self.assertEqual(form.fields['city'].label.lower(), "town/city")
     self.assertEqual(form.fields.get('state'), None)
     self.assertEqual(form.fields['code'].label.lower(), "zip code")
开发者ID:codingjoe,项目名称:django-postal,代码行数:10,代码来源:test_l10n.py


示例8: read

 def read(self, request):        
     iso_code = request.GET.get('country', '')
     json = {}
     form_class = form_factory(country_code=iso_code)
     form_obj = form_class()
     for k, v in form_obj.fields.items():
         if k not in json.keys():
             json[k] = {}
         json[k]['label'] = unicode(v.label)
         json[k]['widget'] = v.widget.render(k, "", attrs={'id': 'id_' + k})
     return json
开发者ID:LYF1999,项目名称:website,代码行数:11,代码来源:handlers.py


示例9: test_incorrect_country_code

 def test_incorrect_country_code(self):
     """
     Tests that we don't throw an exception for an incorrect country code
     """
     no_country_form_class = form_factory("xx")
     self.assertNotEqual(no_country_form_class, None)
     
     form = no_country_form_class()
     
     self.assertEqual(form.fields['line1'].label.lower(), "street")
     self.assertEqual(form.fields['line2'].label.lower(), "area")
     self.assertEqual(form.fields['city'].label.lower(), "city")
     self.assertEqual(form.fields['state'].label.lower(), "state")
     self.assertEqual(form.fields['code'].label.lower(), "zip code")
开发者ID:codingjoe,项目名称:django-postal,代码行数:14,代码来源:test_l10n.py


示例10: test_get_de_address

 def test_get_de_address(self):
     """
     Tests that we get the correct widget for Germny
     """
     german_form_class = form_factory("de")
     self.assertNotEqual(german_form_class, None)
     
     # only use required fields
     test_data = {'code': '12345',}
     form = german_form_class(data=test_data)
     
     self.assertEqual(form.fields['line1'].label.lower(), "street")
     self.assertEqual(form.fields.has_key('line2'), False)
     self.assertEqual(form.fields['city'].label.lower(), "city")
     self.assertEqual(form.fields['code'].label.lower(), "zip code")
开发者ID:codingjoe,项目名称:django-postal,代码行数:15,代码来源:test_l10n.py


示例11: test_get_ie_address

    def test_get_ie_address(self):
        """
        Tests that we get the correct widget for Ireland
        """
        irish_form_class = form_factory("ie")
        self.assertNotEqual(irish_form_class, None)

        # only use required fields
        test_data = {'line1': 'street', 'city': 'Tullamore',
                     'state': 'offaly',  }
        form = irish_form_class(data=test_data)
        
        self.assertEqual(form.fields['line1'].label.lower(), "street")
        self.assertEqual(form.fields['line2'].label.lower(), "area")
        self.assertEqual(form.fields['city'].label.lower(), "town/city")
        self.assertEqual(form.fields['state'].label.lower(), "county")
开发者ID:codingjoe,项目名称:django-postal,代码行数:16,代码来源:test_l10n.py


示例12: test_get_co_address

 def test_get_co_address(self):
     """
     Tests that we get the correct widget for Colombia
     """
     co_form_class = form_factory("co")
     self.assertNotEqual(co_form_class, None)
     test_data = {
         'line1': 'Diagonal 25 G',
         'line2': '#95 a 55',
         'state': 'Bogota D.C.',
     }
     form = co_form_class(data=test_data)
     self.assertEqual(form.fields['line1'].label.lower(), "street")
     self.assertEqual(form.fields['line2'].label.lower(), "number")
     self.assertEqual(form.fields['city'].label.lower(), "city")
     self.assertEqual(form.fields['state'].label.lower(), "department")
     self.assertIsInstance(form.fields['code'].widget, forms.HiddenInput)
开发者ID:NB-Dev,项目名称:django-postal,代码行数:17,代码来源:test_l10n.py


示例13: test_no_localisation

    def test_no_localisation(self):
        postal.settings.POSTAL_ADDRESS_L10N = False
        postal.settings.POSTAL_ADDRESS_LINE1 = ('a', False)
        postal.settings.POSTAL_ADDRESS_LINE2 = ('b', False)
        postal.settings.POSTAL_ADDRESS_CITY = ('c', False)
        postal.settings.POSTAL_ADDRESS_STATE = ('d', False)
        postal.settings.POSTAL_ADDRESS_CODE = ('e', False)
        reload(postal.forms)
        reload(postal.library)

        noloc_form_class = form_factory("nl")
        self.assertNotEqual(noloc_form_class, None)
        test_data = {'code': '1234AB'}
        form = noloc_form_class(data=test_data)
        
        self.assertEqual(form.fields['line1'].label, "a")
        self.assertEqual(form.fields['line2'].label, "b")
        self.assertEqual(form.fields['city'].label, "c")
        self.assertEqual(form.fields['state'].label, 'd')
        self.assertEqual(form.fields['code'].label, "e")
开发者ID:codingjoe,项目名称:django-postal,代码行数:20,代码来源:test_l10n.py


示例14: test_get_it_address

    def test_get_it_address(self):
        """
        Tests that we get the correct widget for Italy
        """
        italian_form_class = form_factory("it")
        self.assertNotEqual(italian_form_class, None)

        # only use required fields
        test_data = {
            'street': 'Piazza Duomo',
            'code': '20100',
            'city': 'Milano',
            'state': 'MI'
        }
        form = italian_form_class(data=test_data)

        self.assertEqual(form.fields['line1'].label.lower(), "street")
        self.assertEqual(form.fields['line2'].label.lower(), "area")
        self.assertEqual(form.fields['state'].label.lower(), "province")
        self.assertEqual(form.fields['city'].label.lower(), "city")
        self.assertEqual(form.fields['code'].label.lower(), "zip code")
开发者ID:LYF1999,项目名称:website,代码行数:21,代码来源:test_l10n.py


示例15: test_get_ar_address

    def test_get_ar_address(self):
        """
        Tests that we get the correct widget for Argentina
        """
        form_class = form_factory("ar")
        self.assertNotEqual(form_class, None)

        # only use required fields
        test_data = {
            'line1': 'Maipu',
            'line2': '270',
            'city': 'Ciudad de Buenos Aires',
            'state': 'B',
            'code': 'C1006ACT',
        }
        form = form_class(data=test_data)

        self.assertEqual(form.fields['line1'].label.lower(), "street")
        self.assertEqual(form.fields['line2'].label.lower(), "number")
        self.assertEqual(form.fields['city'].label.lower(), "city")
        self.assertEqual(form.fields['code'].label.lower(), "zip code")
开发者ID:NB-Dev,项目名称:django-postal,代码行数:21,代码来源:test_l10n.py


示例16: save_address

def save_address(request, customer, prefix):
    # get the shop
    shop = lfs.core.utils.get_default_shop(request)

    # get the country for the address
    country_iso = request.POST.get(prefix + "-country", shop.default_country.code)

    # check have we a valid address
    form_class = form_factory(country_iso)
    valid_address = False
    form_obj = form_class(request.POST, prefix=prefix)
    if form_obj.is_valid():
        valid_address = True

    customer_selected_address = None
    address_attribute = 'selected_' + prefix + '_address'
    existing_address = False
    if hasattr(customer, address_attribute):
        customer_selected_address = getattr(customer, address_attribute)
        if customer_selected_address is not None:
            existing_address = True
            customer_selected_address.line1 = request.POST.get(prefix + "-line1", "")
            customer_selected_address.line2 = request.POST.get(prefix + "-line2", "")
            customer_selected_address.city = request.POST.get(prefix + "-city", "")
            customer_selected_address.state = request.POST.get(prefix + "-state", "")
            customer_selected_address.zip_code = request.POST.get(prefix + "-code", "")
            customer_selected_address.country = Country.objects.get(code=country_iso.lower())
            customer_selected_address.save()
    if not existing_address:
        # no address exists for customer so create one
        customer_selected_address = Address.objects.create(customer=customer,
                                                           line1=request.POST.get(prefix + "-line1", ""),
                                                           line2=request.POST.get(prefix + "-line2", ""),
                                                           city=request.POST.get(prefix + "-city", ""),
                                                           state=request.POST.get(prefix + "-state", ""),
                                                           zip_code=request.POST.get(prefix + "-code", ""),
                                                           country=Country.objects.get(code=country_iso.lower()))
    setattr(customer, address_attribute, customer_selected_address)
    customer.save()
    return valid_address
开发者ID:DenisVasiliev,项目名称:django-lfs,代码行数:40,代码来源:views.py


示例17: render

    def render(self, request, country_iso=None):
        """
        Renders the postal and the additional address form.
        """
        if country_iso is None:
            country_iso = self.address.country.code.upper()

        form_model = form_factory(country_iso)
        postal_form = form_model(initial=self.get_address_as_dict(), data=self.data, prefix=self.type)

        countries = self.get_countries(request)
        postal_form.fields["country"].choices = [(c.code.upper(), c.name) for c in countries]

        address_form_model = self.get_form_model()
        address_form = address_form_model(instance=self.address, data=self.data, prefix=self.type)

        templates = ["lfs/addresses/address_form.html"]
        templates.insert(0, "lfs/addresses/%s_address_form.html" % self.type)
        template = select_template(templates)
        return template.render(RequestContext(request, {
            "postal_form": postal_form,
            "address_form": address_form,
        }))
开发者ID:DanielChu,项目名称:django-lfs,代码行数:23,代码来源:utils.py


示例18: test_ar_widgets

    def test_ar_widgets(self):
        """
        Tests that we get the correct widget for Argentina
        """
        # enable L10N
        postal_settings.POSTAL_ADDRESS_L10N = True

        form_class = form_factory("ar")
        self.assertNotEqual(form_class, None)

        # only use required fields
        test_data = {
            'line1': 'Maipu',
            'line2': '270',
            'city': 'Ciudad de Buenos Aires',
            'state': 'B',
            'code': 'C1006ACT',
        }
        form = form_class(data=test_data)

        from localflavor.ar.forms import ARProvinceSelect, ARPostalCodeField
        self.assertIsInstance(form.fields['state'].widget, ARProvinceSelect)
        self.assertIsInstance(form.fields['code'], ARPostalCodeField)
        self.assertEqual(form.fields['country'].initial, 'AR')
开发者ID:ethirajit,项目名称:onlinepos,代码行数:24,代码来源:test_widgets.py


示例19: addresses

def addresses(request, template_name="lfs/customer/addresses.html"):
    """Provides a form to edit addresses and bank account.
    """
    customer = lfs.customer.utils.get_customer(request)
    shop = lfs.core.utils.get_default_shop(request)

    if request.method == "POST":

        # Validate invoice address
        prefix="invoice"
        country_iso = request.POST.get(prefix + "-country", shop.default_country.code)
        form_class = form_factory(country_iso)
        invoice_form = form_class(request.POST, prefix=prefix)

        # Validate shipping address
        prefix="shipping"
        country_iso = request.POST.get(prefix + "-country", shop.default_country.code)
        form_class = form_factory(country_iso)
        shipping_form = form_class(request.POST, prefix=prefix)

        form = AddressForm(request.POST)
        if form.is_valid() and invoice_form.is_valid() and shipping_form.is_valid():
            save_address(request, customer, INVOICE_PREFIX)
            save_address(request, customer, SHIPPING_PREFIX)
            customer.selected_invoice_address.customer = customer
            customer.selected_invoice_address.firstname = form.cleaned_data['invoice_firstname']
            customer.selected_invoice_address.company_name = form.cleaned_data['invoice_company_name']
            customer.selected_invoice_address.lastname = form.cleaned_data['invoice_lastname']
            customer.selected_invoice_address.phone = form.cleaned_data['invoice_phone']
            customer.selected_invoice_address.email = form.cleaned_data['invoice_email']
            customer.selected_invoice_address.save()
            customer.selected_shipping_address.customer = customer
            customer.selected_shipping_address.firstname = form.cleaned_data['shipping_firstname']
            customer.selected_shipping_address.lastname = form.cleaned_data['shipping_lastname']
            customer.selected_shipping_address.company_name = form.cleaned_data['shipping_company_name']
            customer.selected_shipping_address.phone = form.cleaned_data['shipping_phone']
            customer.selected_shipping_address.email = form.cleaned_data['shipping_email']
            customer.selected_shipping_address.save()
            return HttpResponseRedirect(reverse("lfs_my_addresses"))
    else:
        initial = {}
        if customer:
            if customer.selected_invoice_address is not None:
                initial.update({"invoice_firstname": customer.selected_invoice_address.firstname,
                                "invoice_lastname": customer.selected_invoice_address.lastname,
                                "invoice_phone": customer.selected_invoice_address.phone,
                                "invoice_email": customer.selected_invoice_address.email,
                                "invoice_company_name": customer.selected_invoice_address.company_name,
                                })
            if customer.selected_shipping_address is not None:
                initial.update({"shipping_firstname": customer.selected_shipping_address.firstname,
                                "shipping_lastname": customer.selected_shipping_address.lastname,
                                "shipping_phone": customer.selected_shipping_address.phone,
                                "shipping_email": customer.selected_shipping_address.email,
                                "shipping_company_name": customer.selected_shipping_address.company_name,
                                })

        form = AddressForm(initial=initial)
    return render_to_response(template_name, RequestContext(request, {
        "form": form,
        "shipping_address_inline": address_inline(request, "shipping", form),
        "invoice_address_inline": address_inline(request, "invoice", form),
    }))
开发者ID:DenisVasiliev,项目名称:django-lfs,代码行数:63,代码来源:views.py


示例20: one_page_checkout

def one_page_checkout(request, checkout_form=OnePageCheckoutForm,
    template_name="lfs/checkout/one_page_checkout.html"):
    """One page checkout form.
    """
    # If the user is not authenticated and the if only authenticate checkout
    # allowed we rediret to authentication page.
    shop = lfs.core.utils.get_default_shop(request)
    if request.user.is_anonymous() and \
       shop.checkout_type == CHECKOUT_TYPE_AUTH:
        return HttpResponseRedirect(reverse("lfs_checkout_login"))

    customer = customer_utils.get_or_create_customer(request)
    if request.method == "POST":
        form = checkout_form(request.POST)
        toc = True

        if shop.confirm_toc:
            if "confirm_toc" not in request.POST:
                toc = False
                if form.errors is None:
                    form.errors = {}
                form.errors["confirm_toc"] = _(u"Please confirm our terms and conditions")

        # Validate invoice address
        prefix="invoice"
        country_iso = request.POST.get(prefix + "-country", shop.default_country.code)
        form_class = form_factory(country_iso)
        invoice_form = form_class(request.POST, prefix=prefix)

        # Validate shipping address
        valid_shipping_form = True
        if not request.POST.get("no_shipping"):
            prefix="shipping"
            country_iso = request.POST.get(prefix + "-country", shop.default_country.code)
            form_class = form_factory(country_iso)
            shipping_form = form_class(request.POST, prefix=prefix)
            valid_shipping_form = shipping_form.is_valid()

        if form.is_valid() and invoice_form.is_valid() and valid_shipping_form and toc:
            # save invoice details
            customer.selected_invoice_address.firstname = request.POST.get("invoice_firstname")
            customer.selected_invoice_address.lastname = request.POST.get("invoice_lastname")
            customer.selected_invoice_address.phone = request.POST.get("invoice_phone")
            customer.selected_invoice_address.email = request.POST.get("invoice_email")
            customer.selected_invoice_address.company_name = request.POST.get("invoice_company_name")

            # Create or update invoice address
            valid_invoice_address = save_address(request, customer, INVOICE_PREFIX)
            if valid_invoice_address == False:
                form._errors.setdefault(NON_FIELD_ERRORS, ErrorList([_(u"Invalid invoice address")]))
            else:
                # If the shipping address differs from invoice firstname we create
                # or update the shipping address.
                valid_shipping_address = True
                if not form.cleaned_data.get("no_shipping"):
                    # save shipping details
                    customer.selected_shipping_address.firstname = request.POST.get("shipping_firstname")
                    customer.selected_shipping_address.lastname = request.POST.get("shipping_lastname")
                    customer.selected_shipping_address.phone = request.POST.get("shipping_phone")
                    customer.selected_shipping_address.email = request.POST.get("shipping_email")
                    customer.selected_shipping_address.company_name = request.POST.get("shipping_company_name")

                    valid_shipping_address = save_address(request, customer, SHIPPING_PREFIX)

                if valid_shipping_address == False:
                    form._errors.setdefault(NON_FIELD_ERRORS, ErrorList([_(u"Invalid shipping address")]))
                else:
                    # Payment method
                    customer.selected_payment_method_id = request.POST.get("payment_method")

                    if int(form.data.get("payment_method")) == DIRECT_DEBIT:
                        bank_account = BankAccount.objects.create(
                            account_number=form.cleaned_data.get("account_number"),
                            bank_identification_code=form.cleaned_data.get("bank_identification_code"),
                            bank_name=form.cleaned_data.get("bank_name"),
                            depositor=form.cleaned_data.get("depositor"),
                        )

                        customer.selected_bank_account = bank_account

                    # Save the selected information to the customer
                    customer.save()

                    # process the payment method ...
                    result = lfs.payment.utils.process_payment(request)

                    if result["accepted"]:
                        return HttpResponseRedirect(result.get("next_url", reverse("lfs_thank_you")))
                    else:
                        if "message" in result:
                            form._errors[result.get("message_location")] = result.get("message")
        else:  # form is not valid
            # save invoice details
            customer.selected_invoice_address.firstname = request.POST.get("invoice_firstname")
            customer.selected_invoice_address.lastname = request.POST.get("invoice_lastname")
            customer.selected_invoice_address.phone = request.POST.get("invoice_phone")
            customer.selected_invoice_address.email = request.POST.get("invoice_email")
            customer.selected_invoice_address.company_name = request.POST.get("invoice_company_name")

            # If the shipping address differs from invoice firstname we create
#.........这里部分代码省略.........
开发者ID:DenisVasiliev,项目名称:django-lfs,代码行数:101,代码来源:views.py



注:本文中的postal.library.form_factory函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python encode.multipart_encode函数代码示例发布时间:2022-05-25
下一篇:
Python factories.SitePackageFactory类代码示例发布时间:2022-05-25
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap