Update Address forms to use localflavor USPS_CHOICES

This commit is contained in:
Nathan Chapman 2022-05-30 12:26:32 -06:00
parent 6da6e347a1
commit d22eab79ed
7 changed files with 42 additions and 68 deletions

View File

@ -22,6 +22,7 @@ redis = "*"
psycopg2 = "*" psycopg2 = "*"
usps-api = "*" usps-api = "*"
sentry-sdk = "*" sentry-sdk = "*"
django-localflavor = "*"
[dev-packages] [dev-packages]
django-debug-toolbar = "*" django-debug-toolbar = "*"

33
Pipfile.lock generated
View File

@ -1,7 +1,7 @@
{ {
"_meta": { "_meta": {
"hash": { "hash": {
"sha256": "4f9bdb7dfcf18c751ee33ce2802a254209060702093d0f55503d91029f3f3081" "sha256": "5b74202138e8858b031003879f0a946fbaf0bc974d2378f585525f9c6fefef8b"
}, },
"pipfile-spec": 6, "pipfile-spec": 6,
"requires": { "requires": {
@ -52,11 +52,11 @@
"redis" "redis"
], ],
"hashes": [ "hashes": [
"sha256:d1398cadf30f576266b34370e28e880306ec55f7a4b6307549b0ae9c15663481", "sha256:138420c020cd58d6707e6257b6beda91fd39af7afde5d36c6334d175302c0e14",
"sha256:da31f8eae7607b1582e5ee2d3f2d6f58450585afd23379491e3d9229d08102d0" "sha256:fafbd82934d30f8a004f81e8f7a062e31413a23d444be8ee3326553915958c6d"
], ],
"index": "pypi", "index": "pypi",
"version": "==5.2.6" "version": "==5.2.7"
}, },
"certifi": { "certifi": {
"hashes": [ "hashes": [
@ -142,7 +142,7 @@
"sha256:a0713dc7a1de3f06bc0df5a9567ad19ead2d3d5689b434768a6145bff77c0667", "sha256:a0713dc7a1de3f06bc0df5a9567ad19ead2d3d5689b434768a6145bff77c0667",
"sha256:f184f0d851d96b6d29297354ed981b7dd71df7ff500d82fa6d11f0856bee8035" "sha256:f184f0d851d96b6d29297354ed981b7dd71df7ff500d82fa6d11f0856bee8035"
], ],
"markers": "python_full_version >= '3.6.2' and python_full_version < '4.0.0'", "markers": "python_version < '4' and python_full_version >= '3.6.2'",
"version": "==0.3.0" "version": "==0.3.0"
}, },
"click-plugins": { "click-plugins": {
@ -268,6 +268,14 @@
"index": "pypi", "index": "pypi",
"version": "==21.1" "version": "==21.1"
}, },
"django-localflavor": {
"hashes": [
"sha256:6593865dc671333b3edc88e729e6d384d00b6db7891ef5d3a65db831a40050d2",
"sha256:ac2fa377bbcba4cae95e97077d9e77c7f22b3d93e4845e2e133ba7e664043a44"
],
"index": "pypi",
"version": "==3.1"
},
"django-measurement": { "django-measurement": {
"hashes": [ "hashes": [
"sha256:b2d40b8b56b4e8277130a2a8cbc1f01f597589a636e0ea7dfbc4e4c05d458cef", "sha256:b2d40b8b56b4e8277130a2a8cbc1f01f597589a636e0ea7dfbc4e4c05d458cef",
@ -569,6 +577,13 @@
"markers": "python_version >= '3.5'", "markers": "python_version >= '3.5'",
"version": "==0.19.2" "version": "==0.19.2"
}, },
"python-stdnum": {
"hashes": [
"sha256:374e2b5e13912ccdbf50b0b23fca2c3e0531174805c32d74e145f37756328340",
"sha256:a46e6cf9652807314d369b654b255c86a59f93d18be2834f3d567ed1a346c547"
],
"version": "==1.17"
},
"python3-openid": { "python3-openid": {
"hashes": [ "hashes": [
"sha256:33fbf6928f401e0b790151ed2b5290b02545e8775f982485205a066f874aaeaf", "sha256:33fbf6928f401e0b790151ed2b5290b02545e8775f982485205a066f874aaeaf",
@ -733,7 +748,7 @@
"sha256:44ece4d53fb1706f667c9bd1c648f5469a2ec925fcf3a776667042d645472c14", "sha256:44ece4d53fb1706f667c9bd1c648f5469a2ec925fcf3a776667042d645472c14",
"sha256:aabaf16477806a5e1dd19aa41f8c2b7950dd3c746362d7e3223dbe6de6ac448e" "sha256:aabaf16477806a5e1dd19aa41f8c2b7950dd3c746362d7e3223dbe6de6ac448e"
], ],
"markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4' and python_full_version < '4.0.0'", "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4' and python_version < '4'",
"version": "==1.26.9" "version": "==1.26.9"
}, },
"usps-api": { "usps-api": {
@ -1025,10 +1040,10 @@
}, },
"selenium": { "selenium": {
"hashes": [ "hashes": [
"sha256:866b6dd6c459210662bff922ee7c33162d21920fbf6811e8e5a52be3866a687f" "sha256:ba5b2633f43cf6fe9d308fa4a6996e00a101ab9cb1aad6fd91ae1f3dbe57f56f"
], ],
"index": "pypi", "index": "pypi",
"version": "==4.1.5" "version": "==4.2.0"
}, },
"sniffio": { "sniffio": {
"hashes": [ "hashes": [
@ -1074,7 +1089,7 @@
"sha256:44ece4d53fb1706f667c9bd1c648f5469a2ec925fcf3a776667042d645472c14", "sha256:44ece4d53fb1706f667c9bd1c648f5469a2ec925fcf3a776667042d645472c14",
"sha256:aabaf16477806a5e1dd19aa41f8c2b7950dd3c746362d7e3223dbe6de6ac448e" "sha256:aabaf16477806a5e1dd19aa41f8c2b7950dd3c746362d7e3223dbe6de6ac448e"
], ],
"markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4' and python_full_version < '4.0.0'", "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3, 3.4' and python_version < '4'",
"version": "==1.26.9" "version": "==1.26.9"
}, },
"wsproto": { "wsproto": {

View File

@ -1,52 +0,0 @@
STATE_CHOICES = [
('AL', 'Alabama'),
('AK', 'Alaska'),
('AZ', 'Arizona'),
('AR', 'Arkansas'),
('CA', 'California'),
('CO', 'Colorado'),
('CT', 'Connecticut'),
('DE', 'Delaware'),
('FL', 'Florida'),
('GA', 'Georgia'),
('HI', 'Hawaii'),
('ID', 'Idaho'),
('IL', 'Illinois'),
('IN', 'Indiana'),
('IA', 'Iowa'),
('KS', 'Kansas'),
('KY', 'Kentucky'),
('LA', 'Louisiana'),
('ME', 'Maine'),
('MD', 'Maryland'),
('MA', 'Massachusetts'),
('MI', 'Michigan'),
('MN', 'Minnesota'),
('MS', 'Mississippi'),
('MO', 'Missouri'),
('MT', 'Montana'),
('NE', 'Nebraska'),
('NV', 'Nevada'),
('NH', 'New Hampshire'),
('NJ', 'New Jersey'),
('NM', 'New Mexico'),
('NY', 'New York'),
('NC', 'North Carolina'),
('ND', 'North Dakota'),
('OH', 'Ohio'),
('OK', 'Oklahoma'),
('OR', 'Oregon'),
('PA', 'Pennsylvania'),
('RI', 'Rhode Island'),
('SC', 'South Carolina'),
('SD', 'South Dakota'),
('TN', 'Tennessee'),
('TX', 'Texas'),
('UT', 'Utah'),
('VT', 'Vermont'),
('VA', 'Virginia'),
('WA', 'Washington'),
('WV', 'West Virginia'),
('WI', 'Wisconsin'),
('WY', 'Wyoming'),
]

View File

@ -3,6 +3,7 @@ from django.contrib.auth.forms import UserCreationForm, UserChangeForm
from allauth.account.forms import SignupForm from allauth.account.forms import SignupForm
from .models import Address, User from .models import Address, User
class AddressForm(forms.ModelForm): class AddressForm(forms.ModelForm):
class Meta: class Meta:
model = Address model = Address
@ -22,6 +23,7 @@ class AccountCreateForm(UserCreationForm):
model = User model = User
fields = ('username', 'email') fields = ('username', 'email')
class AccountUpdateForm(UserChangeForm): class AccountUpdateForm(UserChangeForm):
class Meta: class Meta:
model = User model = User
@ -33,6 +35,7 @@ class AccountUpdateForm(UserChangeForm):
'addresses', 'addresses',
) )
class CustomerUpdateForm(forms.ModelForm): class CustomerUpdateForm(forms.ModelForm):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
@ -47,6 +50,13 @@ class CustomerUpdateForm(forms.ModelForm):
'default_shipping_address', 'default_shipping_address',
) )
class UserSignupForm(SignupForm): class UserSignupForm(SignupForm):
first_name = forms.CharField(required=True, widget=forms.TextInput(attrs={'placeholder': 'First name'})) first_name = forms.CharField(
last_name = forms.CharField(required=True, widget=forms.TextInput(attrs={'placeholder': 'Last name'})) required=True,
widget=forms.TextInput(attrs={'placeholder': 'First name'})
)
last_name = forms.CharField(
required=True,
widget=forms.TextInput(attrs={'placeholder': 'Last name'})
)

View File

@ -1,8 +1,7 @@
from django.db import models from django.db import models
from django.urls import reverse from django.urls import reverse
from django.contrib.auth.models import AbstractUser from django.contrib.auth.models import AbstractUser
from localflavor.us.us_states import USPS_CHOICES
from . import STATE_CHOICES
class Address(models.Model): class Address(models.Model):
@ -13,7 +12,7 @@ class Address(models.Model):
city = models.CharField(max_length=256, blank=True) city = models.CharField(max_length=256, blank=True)
state = models.CharField( state = models.CharField(
max_length=2, max_length=2,
choices=STATE_CHOICES, choices=USPS_CHOICES,
blank=True blank=True
) )
postal_code = models.CharField(max_length=20, blank=True) postal_code = models.CharField(max_length=20, blank=True)

View File

@ -39,6 +39,7 @@ INSTALLED_APPS = [
# 3rd Party # 3rd Party
'django_filters', 'django_filters',
'storages', 'storages',
'localflavor',
'debug_toolbar', 'debug_toolbar',
'django_celery_beat', 'django_celery_beat',
'django_celery_results', 'django_celery_results',

View File

@ -6,11 +6,11 @@ from django import forms
from django.conf import settings from django.conf import settings
from django.core.mail import EmailMessage from django.core.mail import EmailMessage
from django.core.exceptions import ValidationError from django.core.exceptions import ValidationError
from localflavor.us.us_states import USPS_CHOICES
from usps import USPSApi, Address from usps import USPSApi, Address
from core.models import Order from core.models import Order
from core import CoffeeGrind from core import CoffeeGrind
from accounts import STATE_CHOICES
from .tasks import contact_form_email from .tasks import contact_form_email
@ -53,7 +53,7 @@ class AddressForm(forms.Form):
street_address_2 = forms.CharField(required=False) street_address_2 = forms.CharField(required=False)
city = forms.CharField() city = forms.CharField()
state = forms.ChoiceField( state = forms.ChoiceField(
choices=STATE_CHOICES choices=USPS_CHOICES
) )
postal_code = forms.CharField() postal_code = forms.CharField()