equal
deleted
inserted
replaced
1 from django import forms |
1 from django import forms |
2 |
2 |
3 from spoken_tut.upload.models import Participant |
3 from spoken_tut.upload.models import Participant |
4 |
4 |
|
5 |
5 class ParticipantForm(forms.ModelForm): |
6 class ParticipantForm(forms.ModelForm): |
6 def clean(self): |
7 def clean_other_lang(self): |
7 """Cleaner for validating Other language field. |
8 """Cleaner for validating Other language field. |
8 """ |
9 """ |
9 cleaned_data = self.cleaned_data |
10 cleaned_data = self.cleaned_data |
10 lang = cleaned_data['language'] |
11 lang = cleaned_data.get('language') |
11 other_lang = cleaned_data['other_lang'] |
12 other_lang = cleaned_data.get('other_lang') |
12 accept = cleaned_data['accept'] |
13 if lang == 'Other' and not other_lang: |
13 if lang == 'Other' and not other_lang: |
14 raise forms.ValidationError('Please fill in the other language field.') |
14 raise forms.ValidationError('Please fill in the other language field.') |
|
15 if accept: |
|
16 raise forms.ValidationError('You need to accept the terms and condition for uploading the data.') |
|
17 |
15 |
18 class Meta: |
16 return other_lang |
19 model = Participant |
|
20 |
17 |
|
18 def clean(self): |
|
19 """Form cleaner for accepting the terms and conditions. |
|
20 """ |
|
21 cleaned_data = self.cleaned_data |
|
22 accept = cleaned_data.get('accept') |
|
23 if not accept: |
|
24 raise forms.ValidationError( |
|
25 'You need to accept the terms and condition for uploading the data.') |
|
26 |
|
27 return cleaned_data |
|
28 |
|
29 class Meta: |
|
30 model = Participant |