1 # -*- coding: utf-8 -*-
3 # This file is part of MIL/PEER, licensed under GNU Affero GPLv3 or later.
4 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
6 from django import forms
7 from django.utils.translation import ugettext as _
8 from django.contrib.auth.models import User
11 class RegistrationForm(forms.Form):
12 first_name = forms.CharField()
13 last_name = forms.CharField()
14 email = forms.EmailField()
15 password = forms.CharField(widget=forms.PasswordInput)
17 def clean_email(self):
18 max_length = User._meta.get_field('username').max_length
19 email = self.cleaned_data['email']
20 if User.objects.filter(username=email).exists():
21 raise forms.ValidationError(_('User with this email address already exists.'))
22 if len(email) > max_length:
23 raise forms.ValidationError(_('Username too long. Max length: %s') % max_length)