Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from crispy_forms.helper import FormHelper
- from crispy_forms.layout import Submit
- from django import forms
- from django.contrib.auth.forms import UserCreationForm, SetPasswordForm
- from user_mgmt.models import AccountUser, Club, Player
- class AccountClubCreationForm(UserCreationForm):
- helper = FormHelper()
- helper.add_input(
- Submit('submit', 'Register', css_class="btn btn-success")
- )
- helper.form_method = 'POST'
- def __init_(self, *args, **kwargs):
- super().__init__(*args, **kwargs)
- self.fields['username'].widget.attrs['placeholder'] = 'username'
- self.fields['email'].widget.attrs['placeholder'] = 'example@example.com'
- self.fields['password1'].widget.attrs['placeholder'] = 'choose your password wisely'
- self.fields['password2'].widget.attrs['placeholder'] = 'ripeta la password inserita'
- def save(self, commit=True):
- user = super().save(commit=False)
- user.is_club = True
- if commit:
- user.save()
- return user
- class Meta:
- model = AccountUser
- fields = (
- 'username',
- 'email',
- 'password1',
- 'password2',
- 'terms_of_service_acceptance',
- )
- class AccountPlayerCreationForm(UserCreationForm):
- helper = FormHelper()
- helper.add_input(
- Submit('submit', 'Register', css_class="btn btn-success")
- )
- helper.form_method = 'POST'
- def __init_(self, *args, **kwargs):
- super().__init__(*args, **kwargs)
- self.fields['username'].widget.attrs['placeholder'] = 'username'
- self.fields['email'].widget.attrs['placeholder'] = 'example@example.com'
- self.fields['password2'].widget.attrs['placeholder'] = 'ripeta la password inserita'
- def save(self, commit=True):
- user = super().save(commit=False)
- user.is_club = False
- if commit:
- user.save()
- return user
- class Meta:
- model = AccountUser
- fields = (
- 'username',
- 'email',
- 'password1',
- 'password2',
- 'terms_of_service_acceptance',
- )
- class ClubCreationForm(UserCreationForm):
- def __init_(self, *args, **kwargs):
- super().__init__(*args, **kwargs)
- self.fields['club_name'].widget.attrs['placeholder'] = 'Nome del centro sportivo'
- self.fields['middle_name'].widget.attrs['placeholder'] = 'Se presente'
- self.fields['city'].widget.attrs['placeholder'] = 'Città'
- self.helper = FormHelper()
- self.helper.add_input(
- Submit('submit', 'Register', css_class='btn btn-success')
- )
- class Meta:
- model = Club
- fields = (
- 'first_name',
- 'middle_name',
- 'last_name',
- 'club_name',
- 'city',
- )
- class PlayerCreationForm(UserCreationForm):
- email = forms.EmailField(required=True)
- def __init__(self, *args, **kwargs):
- super().__init__(*args, **kwargs)
- self.fields['middle_name'].widget.attrs['placeholder'] = 'Se presente'
- self.helper = FormHelper()
- self.helper.add_input(
- Submit('submit', 'Register', css_class='btn btn-success')
- )
- class Meta:
- model = Player
- fields = (
- 'first_name',
- 'middle_name',
- 'last_name',
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement