Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from django import forms
- from . import models
- class LoginForm(forms.Form):
- username = forms.CharField(
- widget=forms.TextInput(
- attrs={
- 'class': 'au-input au-input--full',
- 'placeholder': 'Username',
- 'required': True
- },
- )
- )
- password = forms.CharField(
- widget=forms.PasswordInput(
- attrs={
- 'class': 'au-input au-input--full',
- 'placeholder': 'Password',
- 'required': True
- }
- )
- )
- class PositionSearchForm(forms.Form):
- search_field = forms.CharField(
- widget=forms.TextInput(
- attrs={
- 'class': 'form-control',
- 'placeholder': 'Search for positions',
- 'required': True
- },
- ),
- help_text='Minimum length is 3',
- min_length=3
- )
- class NewPositionForm(forms.ModelForm):
- class Meta:
- model = models.Positions
- fields = ('position_name',)
- widgets = {
- 'position_name': forms.TextInput(
- attrs={
- 'class': 'form-control',
- 'placeholder': 'Position Name',
- 'required': True
- }
- )
- }
- from django import forms
- from django.contrib.auth.forms import ReadOnlyPasswordHashField
- class RegisterForm(forms.ModelForm):
- password = forms.CharField(widget=forms.PasswordInput)
- password2 = forms.CharField(label='Confirm password', widget=forms.PasswordInput)
- class Meta:
- model = models.User
- fields = ('email',)
- def clean_email(self):
- email = self.cleaned_data.get('email')
- qs = models.User.objects.filter(email=email)
- if qs.exists():
- raise forms.ValidationError("email is taken")
- return email
- def clean_password2(self):
- # Check that the two password entries match
- password1 = self.cleaned_data.get("password1")
- password2 = self.cleaned_data.get("password2")
- if password1 and password2 and password1 != password2:
- raise forms.ValidationError("Passwords don't match")
- return password2
- class UserAdminCreationForm(forms.ModelForm):
- """A form for creating new users. Includes all the required
- fields, plus a repeated password."""
- password1 = forms.CharField(label='Password', widget=forms.PasswordInput)
- password2 = forms.CharField(label='Password confirmation', widget=forms.PasswordInput)
- class Meta:
- model = models.User
- fields = ('email',)
- def clean_password2(self):
- # Check that the two password entries match
- password1 = self.cleaned_data.get("password1")
- password2 = self.cleaned_data.get("password2")
- if password1 and password2 and password1 != password2:
- raise forms.ValidationError("Passwords don't match")
- return password2
- def save(self, commit=True):
- # Save the provided password in hashed format
- user = super(UserAdminCreationForm, self).save(commit=False)
- user.set_password(self.cleaned_data["password1"])
- if commit:
- user.save()
- return user
- class UserAdminChangeForm(forms.ModelForm):
- """A form for updating users. Includes all the fields on
- the user, but replaces the password field with admin's
- password hash display field.
- """
- password = ReadOnlyPasswordHashField()
- class Meta:
- model = models.User
- fields = ('email', 'password', 'active', 'admin')
- def clean_password(self):
- # Regardless of what the user provides, return the initial value.
- # This is done here, rather than on the field, because the
- # field does not have access to the initial value
- return self.initial["password"]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement