Skip to content

# Forms

## Fields

class terminusgps.django.forms.fields.AddressField(fields=(), widget=<terminusgps.django.forms.widgets.AddressWidget object>, *args, **kwargs)
  compress(data_list: Sequence[str]) → customerAddressType

    Compresses `data_list` into a `customerAddressType`.

class terminusgps.django.forms.fields.CreditCardField(fields=(), widget=<terminusgps.django.forms.widgets.CreditCardWidget object>, *args, **kwargs)
  compress(data_list: Sequence[str]) → creditCardType

    Compresses `data_list` into a `creditCardType`.

## Widgets

class terminusgps.django.forms.widgets.AddressWidget(widgets=(), attrs: dict | None = None)
  decompress(value: customerAddressType | None) → list[str | None]

    Decompresses a `customerAddressType` into a list of strings.

  property media

    Media for a multiwidget is the combination of all media of the subwidgets.

class terminusgps.django.forms.widgets.CreditCardWidget(widgets=(), attrs: dict | None = None)
  decompress(value: creditCardType | None) → list[str | None]

    Decompresses a `creditCardType` into a list of strings.

  property media

    Media for a multiwidget is the combination of all media of the subwidgets.

## Usage

    from django import forms
    from terminusgps.django.forms import AddressField, CreditCardField

    class MyCustomForm(forms.Form):
        first_name = forms.CharField(label="First Name", max_length=64)
        last_name = forms.CharField(label="Last Name", max_length=64)
        phone = forms.CharField(label="Phone #")
        address = AddressField(label="Address")
        credit_card = CreditCardField(label="Credit Card")

    form_data = {
        "first_name": "TestFirstName",
        "last_name": "TestLastName",
        "phone": "555-555-5555",
        "address_0": "123 Main St.", # Street
        "address_1": "Houston", # City
        "address_2": "Texas", # State
        "address_3": "77065", # Zip
        "address_4": "US", # Country (2 chars)
        "credit_card_0": "411111111111111", # Credit card number
        "credit_card_1": "1", # Expiration month
        "credit_card_2": "35", # Expiration year
        "credit_card_3": "444", # Credit card ccv code
    }
    form = MyCustomForm(form_data)

    print(f"{form.is_valid() = }") # True
    print(f"{type(form.clean()['address']) = }") # <authorizenet.apicontractsv1.customerAddressType>
    print(f"{type(form.clean()['credit_card']) = }") # <authorizenet.apicontractsv1.paymentType>