class ProfileRegistration forms Form def __init__ self city institutio

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
class ProfileRegistration(forms.Form):
def __init__(self, city, institution_type, *args, **kwargs):
self.city = city
self.institution_type = institution_type
self.base_fields['institution'].queryset = Institution.objects.filter(city=self.city, institution_type=self.institution_type)
super(ProfileRegistration, self).__init__(*args, **kwargs)
institution = forms.ModelChoiceField(Institution.objects.all(), widget=forms.Select(attrs={'class': 'confirm'}))
start_year = forms.ChoiceField(choices=YEAR_CHOICES, widget=forms.Select(attrs={'class': 'confirm'}))
end_year = forms.ChoiceField(choices=YEAR_CHOICES, widget=forms.Select(attrs={'class': 'confirm'}))
email = forms.EmailField(widget=forms.TextInput(attrs={'class': 'confirm'}))
first_name = forms.CharField(max_length=30, widget=forms.TextInput(attrs={'class': 'confirm'}))
last_name = forms.CharField(max_length=30, widget=forms.TextInput(attrs={'class': 'confirm'}))
old_last_name = forms.CharField(max_length=30, required=False, widget=forms.TextInput(attrs={'class': 'confirm'}))
country = forms.ModelChoiceField(Country.objects.all(), widget=forms.Select(attrs={'class': 'confirm'}))
city = forms.CharField(max_length=30, widget=forms.TextInput(attrs={'class': 'confirm'}))
gender = forms.ChoiceField(choices=SEX_CHOICES, widget=forms.Select(attrs={'class': 'confirm'}))
year = forms.ChoiceField(choices=YEAR_CHOICES, widget=forms.Select(attrs={'class': 'confirm'}))
month = forms.ChoiceField(choices=MONTH_CHOICES, widget=forms.Select(attrs={'class': 'confirm'}))
day = forms.ChoiceField(choices=DAY_CHOICES, widget=forms.Select(attrs={'class': 'confirm'}))
password = forms.CharField(min_length=4, max_length=30, widget=forms.PasswordInput(attrs={'class': 'confirm'}))
def clean_email(self):
if get_object_or_None(Profile, username=self.cleaned_data['email'].lower()):
raise forms.ValidationError(u'This email adress is already used')
return self.cleaned_data