65 lines
1.6 KiB
Python
65 lines
1.6 KiB
Python
from django import forms
|
|
from django.contrib.auth.forms import UserCreationForm, UserChangeForm
|
|
from allauth.account.forms import SignupForm
|
|
from captcha.fields import CaptchaField
|
|
from .models import Address, User
|
|
|
|
|
|
class AddressForm(forms.ModelForm):
|
|
class Meta:
|
|
model = Address
|
|
fields = (
|
|
'first_name',
|
|
'last_name',
|
|
'street_address_1',
|
|
'street_address_2',
|
|
'city',
|
|
'state',
|
|
'postal_code',
|
|
)
|
|
|
|
|
|
class AccountCreateForm(UserCreationForm):
|
|
class Meta:
|
|
model = User
|
|
fields = ('username', 'email')
|
|
|
|
|
|
class AccountUpdateForm(UserChangeForm):
|
|
class Meta:
|
|
model = User
|
|
fields = (
|
|
'first_name',
|
|
'last_name',
|
|
'email',
|
|
'default_shipping_address',
|
|
'addresses',
|
|
)
|
|
|
|
|
|
class CustomerUpdateForm(forms.ModelForm):
|
|
def __init__(self, *args, **kwargs):
|
|
super().__init__(*args, **kwargs)
|
|
self.fields['default_shipping_address'].queryset = kwargs['instance'].addresses
|
|
|
|
class Meta:
|
|
model = User
|
|
fields = (
|
|
'first_name',
|
|
'last_name',
|
|
'email',
|
|
'default_shipping_address',
|
|
)
|
|
|
|
|
|
class UserSignupForm(SignupForm):
|
|
first_name = forms.CharField(
|
|
required=True,
|
|
widget=forms.TextInput(attrs={'placeholder': 'First name'})
|
|
)
|
|
last_name = forms.CharField(
|
|
required=True,
|
|
widget=forms.TextInput(attrs={'placeholder': 'Last name'})
|
|
)
|
|
captcha = CaptchaField()
|