upload/forms.py
changeset 18 07408d1ced76
parent 17 08a47999f316
child 19 6af9056ccac9
equal deleted inserted replaced
17:08a47999f316 18:07408d1ced76
     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