| 163 | | #class UsernameForm(forms.ModelForm): |
| 164 | | # """ |
| 165 | | # form for input the username, used in auth.login() |
| 166 | | # """ |
| 167 | | # class Meta: |
| 168 | | # model = User |
| 169 | | # fields=("username",) |
| 170 | | |
| 171 | | class UsernameForm(forms.Form): |
| 172 | | """ |
| 173 | | FIXME: If we use ModelForm from above, we always get the form error: |
| 174 | | User with this Username already exists. |
| 175 | | Why? |
| 176 | | """ |
| 177 | | username = forms.CharField(max_length=30, help_text=_( |
| 178 | | "Required. 30 characters or fewer. Alphanumeric characters only" |
| 179 | | " (letters, digits and underscores)." |
| 180 | | ) |
| 181 | | ) |
| 182 | | |
| 183 | | #class PasswordForm(forms.ModelForm): |
| 184 | | # """ |
| 185 | | # form for input the username, used in auth._sha_login() |
| 186 | | # """ |
| 187 | | # class Meta: |
| 188 | | # model = User |
| 189 | | # fields=("password",) |
| 190 | | class PasswordForm(forms.Form): |
| 191 | | """ |
| 192 | | Same 'User with this Username already exists.' problem from above. |
| 193 | | """ |
| 194 | | password = forms.CharField(max_length=128) |
| 195 | | |
| 196 | | |
| 197 | | class ResetForm(forms.Form): |
| 198 | | """ |
| 199 | | We should not use a ModelForm from the User model, because, the email |
| 200 | | is required here or we must patch a ModelForm. |
| 201 | | """ |
| 202 | | username = forms.CharField(max_length=30, help_text=_( |
| 203 | | "Required. 30 characters or fewer. Alphanumeric characters only" |
| 204 | | " (letters, digits and underscores)." |
| 205 | | ) |
| 206 | | ) |
| 207 | | email = forms.EmailField() |
| | 163 | class ModelForm2(forms.ModelForm): |
| | 164 | def validate_unique(self): |
| | 165 | """ |
| | 166 | Don't validate unique fields. |
| | 167 | We used a ModelForm only for generating the forms and not for |
| | 168 | create/update any database data. So a field unique Test would like |
| | 169 | generate Errors like: |
| | 170 | User with this Username already exists. |
| | 171 | """ |
| | 172 | pass |
| | 173 | |
| | 174 | |
| | 175 | class UsernameForm(ModelForm2): |
| | 176 | """ |
| | 177 | form for input the username, used in auth.login() |
| | 178 | """ |
| | 179 | class Meta: |
| | 180 | model = User |
| | 181 | fields=("username",) |
| | 182 | |
| | 183 | |
| | 184 | class PasswordForm(ModelForm2): |
| | 185 | """ |
| | 186 | form for input the username, used in auth._sha_login() |
| | 187 | """ |
| | 188 | class Meta: |
| | 189 | model = User |
| | 190 | fields=("password",) |
| | 191 | |
| | 192 | |
| | 193 | class ResetForm(ModelForm2): |
| | 194 | """ |
| | 195 | from for input username and email, used in auth.pass_reset() |
| | 196 | """ |
| | 197 | def __init__(self, *args, **kwargs): |
| | 198 | super(ResetForm, self).__init__(*args, **kwargs) |
| | 199 | # User.email is normaly a not required field, here it's required! |
| | 200 | self.fields['email'].required = True |
| | 201 | |
| | 202 | class Meta: |
| | 203 | model = User |
| | 204 | fields=("username","email") |