forms.py 752 B

1234567891011121314151617181920212223242526
  1. from django.forms import ModelForm, ValidationError
  2. from django.contrib.auth.forms import PasswordResetForm as AuthPasswordResetForm
  3. from adhesions.models import User
  4. from .models import Profile
  5. class UserForm(ModelForm):
  6. class Meta:
  7. model = User
  8. fields = ('email',)
  9. class ProfileForm(ModelForm):
  10. class Meta:
  11. model = Profile
  12. fields = ('common_name', 'phone_number', 'address', 'ssh_keys',)
  13. class PasswordResetForm(AuthPasswordResetForm):
  14. def clean_email(self):
  15. email = self.cleaned_data['email']
  16. users = User.objects.filter(email__iexact=email)
  17. if not users.exists():
  18. raise ValidationError('Aucun utilisateur connu avec cette adresse e-mail.')
  19. return email