forms py class ProfileRegistration forms Form def __init__ self city i

 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
28
29
30
31
32
#forms.py
class ProfileRegistration(forms.Form):
def __init__(self, city, institution_type, *args, **kwargs):
self.city = city
self.institution_type = institution_type
super(ProfileRegistration, self).__init__(*args, **kwargs)
institution = forms.ModelChoiceField(Institution.objects.filter(city=self.city, institution_type=self.institution_type), 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'}))
#views.py
@render_to("community/register_and_join.html")
def register_and_join(request, city):
city = get_object_or_404(City, slug=city)
institution_type = InstitutionType.objects.get(slug="school")
form = ProfileRegistration(city, institution_type)
return {'form': form}